Submission #1279947

#TimeUsernameProblemLanguageResultExecution timeMemory
1279947tawwieKnapsack (NOI18_knapsack)C++20
0 / 100
1 ms560 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ cin.tie(NULL)->ios_base::sync_with_stdio(false); int s, n; cin >> s >> n; //vector<vector<ll>> dp(n+1, vector<ll>(s+1, 0LL)); vector<ll> dp(s+1, 0LL); for(int i=1; i<=n; i++){ ll v, w, k; cin >> v >> w >> k; // value, weight, copies for(int j=s; j>=w; j--){ for(ll d=w; d<=min(ll(j), k*w); d+=w){ // d is cost of some k_i copies of an item dp[j] = max(dp[j], dp[j-d] + v * d / w); } } for(auto j : dp) cout << j << ' '; cout << '\n'; } //for(auto i : dp){for(auto j : i) cout << j << ' '; cout << '\n';} cout << dp[s]; return 0; } /* 15 3 1000000000 4 1000000000 100 3 100 1 5 2 */
#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...