Submission #1099195

#TimeUsernameProblemLanguageResultExecution timeMemory
1099195coin_Knapsack (NOI18_knapsack)C++14
49 / 100
198 ms262144 KiB
#include <bits/stdc++.h> #define int long long #define endl '\n' #define fi first #define se second using namespace std; signed main(){ ios_base::sync_with_stdio(0); cin.tie(nullptr); int s, n; cin >> s >> n; if (n == 1){ int v, w, k; cin >> v >> w >> k; int ans = 0; while(s >= w && k > 0){ s -= w; ans += v; k--; } cout << ans; return 0; } vector<pair<int, int>> stuff; for (int i = 0; i < n; i++){ int v, w, k; cin >> v >> w >> k; for (int j = 0; j < k; j++){ stuff.push_back({v, w}); } } int num = stuff.size(); vector<int> dp(s+1, 0); for (int i = 0; i < num; i++){ for (int j = s; j >= stuff[i].se; j--){ dp[j] = max(dp[j], dp[j-stuff[i].se] + stuff[i].fi); } } cout << dp[s]; }
#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...