Submission #682890

#TimeUsernameProblemLanguageResultExecution timeMemory
682890matuKnapsack (NOI18_knapsack)C++14
73 / 100
869 ms524 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e2 + 1, S = 2e3+ 1; int n, s; //vector<vector<long long>> dp(N, vector<long long>(S)); vector<long long> dp1(S), dp2(S); vector<int> h(N), w(N), k(N); int main(){ cin >> s >> n; for(int i = 1; i <= n; i++){ cin >> w[i] >> h[i] >> k[i]; } long long pra = h[1], car = w[1]; while(k[1] && pra <= s){ dp1[pra] = car; pra += h[1]; car += w[1]; k[1]--; } for(int i = 2; i <= n; i++){ for(int x = 1; x <= s; x++){ dp2[x] = max(dp2[x], dp1[x]); long long acum = h[i], pr = w[i], zaz = k[i]; while(acum <= s && zaz){ if(x >= acum && dp2[x] < dp1[x - acum] + pr){ dp2[x] = dp1[x - acum] + pr; } acum += h[i]; pr += w[i]; zaz--; } } swap(dp2, dp1); } long long ans = 0; for(int i = 1; i <= s; i++){ ans = max(ans, dp1[i]); } cout << ans; }
#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...