Submission #1326046

#TimeUsernameProblemLanguageResultExecution timeMemory
1326046c0d3xx_Knapsack (NOI18_knapsack)C++20
73 / 100
1094 ms424 KiB
#include <bits/stdc++.h>
#define maxn 2003
#define pii pair<ll, ll> 
#define tpe tuple<int, int, int>
#define MOD 1000000007
#define ll long long
#define lim 44725
#define file "mind"
#define base 131
using namespace std;

int n, c;
ll d[maxn];
int main() {
    
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cin >> c >> n;
  for(int i = 1; i <= n; i++) {
    int w, v, k; 
    cin >> v >> w >> k;
    for(int p = 1; k > 0; p *= 2) {
      int cur = min(p, k);
      ll new_w = 1ll * w * cur;
      ll new_v = 1ll * v * cur;
      for(int j = c; j >= new_w; j--) 
        d[j] = max(d[j], d[j-new_w] + new_v);
        
      k -= cur;
    }
  }
  
  cout << d[c];
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...