Submission #682883

#TimeUsernameProblemLanguageResultExecution timeMemory
682883matuKnapsack (NOI18_knapsack)C++14
73 / 100
163 ms3540 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<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){ dp[1][pra] = car; pra += h[1]; car += w[1]; k[1]--; } for(int i = 2; i <= n; i++){ for(int x = 1; x <= s; x++){ dp[i][x] = max(dp[i][x], dp[i - 1][x]); long long acum = h[i], pr = w[i], zaz = k[i]; while(acum <= s && zaz){ if(x >= acum && dp[i][x] < dp[i - 1][x - acum] + pr){ dp[i][x] = dp[i - 1][x - acum] + pr; } acum += h[i]; pr += w[i]; zaz--; } } } long long ans = 0; for(int i = 1; i <= s; i++){ ans = max(ans, dp[n][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...