Submission #932444

#TimeUsernameProblemLanguageResultExecution timeMemory
932444ironicKnapsack (NOI18_knapsack)C++17
37 / 100
1058 ms27564 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; void solve(){ int s, n; cin >> s >> n; vector<int> W, V; int v, w, r; for(int i = 0; i<n; i++){ cin >> v >> w >> r; while(r--){ W.push_back(w); V.push_back(v); } } n = W.size(); int a[s+1]{}; fill(a, a+s+1, -1e9); a[0] = 0; for(int i = 0; i<n; i++){ for(int j = s; j>=W[i]; j--){ a[j] = max(a[j], a[j-W[i]] + V[i]); } } int best = 0; for(int i = 0; i<=s; i++) best = max(best, a[i]); cout << best << '\n'; } signed main() { // #ifndef LOCAL // freopen(".in","r",stdin); // freopen(".out","w",stdout); // #endif ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; // cin >> t; while(t--) solve(); }
#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...