Submission #541252

#TimeUsernameProblemLanguageResultExecution timeMemory
541252gromperenKnapsack (NOI18_knapsack)C++14
37 / 100
1076 ms340 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int main(){ ios::sync_with_stdio(0); cin.tie(0); int s, n; cin >> s >> n; vector<int> v(n), w(n), k(n); map<int, vector<pair<int,int>>> wghts; for (int i = 0; i < n; ++i) { cin >> v[i] >> w[i] >> k[i]; wghts[w[i]].push_back({v[i], k[i]}); } vector<ll> dp(s+1); for (int i = 0; i< n; ++i) { for (int j = s; j >= w[i]; --j) { for (int t = 0; t <= k[i]; ++t) { if (j >= w[i] * t) { dp[j] = max(dp[j], dp[j - w[i] * t] + v[i] * t); } } } } cout << dp[s] << "\n"; return 0; }
#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...