Submission #932460

#TimeUsernameProblemLanguageResultExecution timeMemory
932460ironicKnapsack (NOI18_knapsack)C++17
49 / 100
203 ms262144 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; void solve(){ int s, n; cin >> s >> n; vector<int> W, V; ll v, w, r; if(n==1){ cin >> v >> w >> r; cout << min(s/w, r) * v << '\n'; return; } 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...