Submission #975625

#TimeUsernameProblemLanguageResultExecution timeMemory
975625vjudge1Knapsack (NOI18_knapsack)C++17
29 / 100
2 ms1992 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define v(a) vector<a> int main(){ ll s, n; cin >> s >> n; v(v(ll)) dp(n, v(ll)(s+1, 0)); v(ll) val(n), w(n), k(n); for(int i = 0; i < n; i++) cin >> val[i] >> w[i] >> k[i]; for(int j = 0; j <= s; j++){ if(j >= w[0]){ ll pos = j/w[0]; // cout << pos << '\n'; if(pos > k[0]) pos = k[0]; dp[0][j] = val[0]*pos; } } for(int i = 1; i < n; i++){ for(int j = 0; j <= s; j++){ dp[i][j] = dp[i-1][j]; // if(i == 2 && j == s) cout << dp[i][j] << " " << dp[i-1][j] << endl; if(j >= w[i]){ ll pos = j/w[i]; if(pos > k[i]){ pos = k[i]; } // cout << (j-pos*w[i]) << endl; dp[i][j] = max(dp[i][j], dp[i-1][j-(pos*w[i])] + val[i]*pos); } } } ll ans = 0; // for(int i = 0; i < n; i++){ // for(int j = 0; j <= s; j++){ // cout << dp[i][j] << " "; // } // cout << endl; // } for(int j = 0; j <= s; j++) ans = max(ans, dp[n-1][j]); 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...