Submission #475624

# Submission time Handle Problem Language Result Execution time Memory
475624 2021-09-23T13:54:20 Z vishnu_sujith Knapsack (NOI18_knapsack) C++17
0 / 100
131 ms 262148 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef DEBUG
#define LOG(...) cerr << "[" << #__VA_ARGS__ << "]: " << repr(__VA_ARGS__) << endl;
#define MSG(args) cerr << args << "\n";
#define debug(x) x
#else
#define LOG(...)
#define MSG(args)
#define debug(x)
#endif

#define mp make_pair
#define pb push_back
#define sz(x) (int((x).size()))
#define ms(x, v) memset((x), v, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define endl '\n'

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<pii>;
using vvi = vector<vi>;

const int mxN = int(1e5) + 10;

int n, S;
ll v[mxN], w[mxN], k[mxN], memo[mxN][2005];

ll solve(int i, ll s) {
  if (i >= n || s <= 0) return 0LL;
  else if (memo[i][s] != -1) return memo[i][s];

  ll res = 0;
  for (int j = 0; j <= k[i]; ++j) {
    if (s - (1LL * j * w[i]) >= 0)
      res = max(res, solve(i + 1, s - (1LL * j * w[i])) + v[i] * j);
    else
      break;
  }
  return memo[i][s] = res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  ms(memo, 0xff);

  cin >> S >> n;
  for (int i = 0; i < n; ++i)
    cin >> v[i] >> w[i] >> k[i];
  cout << solve(0, S) << endl;

  return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 107 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 131 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 131 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 107 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 107 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -