Submission #1088633

#TimeUsernameProblemLanguageResultExecution timeMemory
1088633damamilaKnapsack (NOI18_knapsack)C++14
73 / 100
179 ms262144 KiB
#include <bits/stdc++.h> using namespace std; //~ #define int long long signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int s, n; cin >> s >> n; vector<vector<int>> items(s+1); for (int i = 0; i < n; i++) { int v, w, k; cin >> v >> w >> k; int tmp = min(k, s/w); for (int i = 0; i < tmp; i++) items[w].push_back(v); } vector<int> dp(s+1, 0); for (int i = 1; i <= s; i++) { sort(items[i].rbegin(), items[i].rend()); //~ cout << i << ": " << endl; int tmp = items[i].size(); int sz = min(tmp, s/i); for (int j = 0; j < sz; j++) { int v = items[i][j]; //~ cout << j << " " << v << endl; for (int k = s; k >= i; k--) { dp[k] = max(dp[k], dp[k-i]+v); //~ cout << "HERE: " << k << " " << dp[k] << endl; } } } cout << dp[s] << 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...