Submission #551056

#TimeUsernameProblemLanguageResultExecution timeMemory
551056DevigoKnapsack (NOI18_knapsack)C++14
29 / 100
3 ms468 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; struct item { ll val, wt, k; }; int main() { ios::sync_with_stdio(0); cin.tie(0); ll s, n; cin >> s >> n; vector<bool> pos(s+1,0); pos[0] = 1; vector<ll> v(s+1,0); vector<item> it(n); for(int i=0; i<n; i++) { cin >> it[i].val >> it[i].wt >> it[i].k; } ll mx = 0; for(ll i=0; i<n; i++) { for(ll j=s-it[i].wt; j>=0; j--) { if(pos[j]) { ll cg = min(it[i].k,s); for(ll m=1; m<=cg; m++) { if(m*it[i].wt <= s) { v[j+(m*it[i].wt)] = max(v[j+(m*it[i].wt)], v[j]+(m*it[i].val)); pos[j+(m*it[i].wt)] = 1; } else break; } } } } for(int i=1; i<=s; i++) mx = max(mx,v[i]); cout << mx << "\n"; return 0; }
#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...