Submission #563987

#TimeUsernameProblemLanguageResultExecution timeMemory
563987NeriWKnapsack (NOI18_knapsack)C++17
29 / 100
464 ms3468 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vll; typedef vector<vll> vvll; typedef pair<ll, int> pill; typedef vector<pill> vpill; typedef vector<vpill> vvpill; int main() { //freopen("..\\io\\input.txt", "r", stdin); //freopen("..\\io\\output.txt", "w", stdout); int s, n; cin >> s >> n; vll k(n+1, 0); vll v(n+1, 0); vll w(n+1, 0); vvpill dp(n+1, vpill(s+1, {0,0})); for(int i = 1; i <= n; i++) { cin >> v[i] >> w[i] >> k[i]; } for(int i = 1; i <= n; i++) { for(int m = 1; m <= w[i]; m++) { for(int j = m; j <= s; j+=w[i]) { /*if(j >= w[i] && (j-m)%(k[i]*w[i]) == 0) { for(int l = 0; l <= k[i]; l++) { dp[i][j] = max(dp[i][j], ) } }*/ if(j >= w[i] && dp[i][j-w[i]].second < k[i]) { if(dp[i][j].first < dp[i][j-w[i]].first + v[i] || (dp[i][j].first == dp[i][j - w[i]].first && dp[i][j].second > dp[i][j-w[i]].second + 1)) { dp[i][j] = dp[i][j-w[i]]; dp[i][j].first += v[i]; dp[i][j].second++; } } if(j >= w[i]*k[i]) { /*if(j == 4 && i == 2) { cout << dp[i][j].first << ", " << dp[i-1][j - w[i]*k[i]].first + v[i]*k[i] << "\n"; }*/ if(dp[i][j].first < dp[i-1][j - w[i]*k[i]].first + v[i]*k[i]) { dp[i][j] = {dp[i-1][j-w[i]*k[i]].first + v[i]*k[i], k[i]}; } } if(dp[i][j].first < dp[i][j-1].first || (dp[i][j].first == dp[i][j-1].first && dp[i][j].second > dp[i][j-1].second)) { dp[i][j] = dp[i][j-1]; } if(dp[i][j].first <= dp[i-1][j].first) { dp[i][j] = dp[i-1][j]; dp[i][j].second = 0; } } for(int j = 1; j <= s; j++) { dp[i][j] = max(dp[i][j], dp[i][j-1]); } } } /*for(int i = 1; i <= n; i++) { for(int j = 0; j <= s; j++) { cout << dp[i][j].first << ", " << dp[i][j].second << " -> "; } cout << "\n"; }*/ cout << dp[n][s].first; }
#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...