Submission #780544

#TimeUsernameProblemLanguageResultExecution timeMemory
780544makanhuliaKnapsack (NOI18_knapsack)C++17
0 / 100
2 ms1876 KiB
#include<bits/stdc++.h> using namespace std; #define ioss ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define int long long #define pii pair<int, int> #define fi first #define se second #define pb push_back int t, n; int l[100004], e[100004], k[100004]; signed main() { ioss; cin >> t >> n; for(int i = 1; i <= n; i++) cin >> l[i] >> e[i] >> k[i]; int dp[n+2][t+2] = {}; for(int i = 1; i <= n; i++) { for(int j = 0; j <= t; j++) { if(j == 0) dp[i][j] = 0; else { for(int x = 1; x <= k[i-1]; x++) { if(x*e[i-1] > j) break; dp[i][j] = max(dp[i-1][j-x*e[i-1]]+x*l[i-1], dp[i-1][j]); } } } } cout << dp[n][t] << endl; }
#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...