Submission #633462

#TimeUsernameProblemLanguageResultExecution timeMemory
633462a_aguiloKnapsack (NOI18_knapsack)C++17
12 / 100
1 ms212 KiB
#include<bits/stdc++.h> using namespace std; typedef vector<long long int> vi; typedef vector<vi> vvi; vi dp; vi values, weight, freqs; int S, N; int main(){ cin >> S >> N; dp = vi(S+1, 0); values = vi(N); weight = vi(N); freqs = vi(N); for(int i = 0; i < N; ++i) cin >> values[i] >> weight[i] >> freqs[i]; unordered_set<int> pos; pos.insert(0); for(int i = 0; i < N; ++i){ vector<int> add; for(int p: pos){ for(int reps = 1; reps <= freqs[i]; ++reps){ int nextW = p + weight[i]*reps; if(nextW <= S) { dp[nextW] = max(dp[nextW], dp[p] + values[i]*reps); add.push_back(nextW); } else break; } } for(int j: add) pos.insert(j); add.clear(); } long long int ans = 0; for(long long int n: dp) ans = max(ans, n); cout << ans << endl; 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...