Submission #1184095

#TimeUsernameProblemLanguageResultExecution timeMemory
1184095sigmalordKnapsack (NOI18_knapsack)C++20
0 / 100
0 ms524 KiB
#include <bits/stdc++.h> using namespace std; long long n,s,dp[2005]; int main (){ ios_base::sync_with_stdio(false); cin.tie(NULL); memset(dp,0,sizeof dp); cin >> s >> n; for (int i = 1; i <= n; i++){ long long w,v,a; cin >> v >> w >> a; if (w * a >= s){ for (int j = w; j <= s; j++){ dp[j] = max(dp[j],dp[j - w]); } } else{ long long temp = 1; while (a > 0){ long long take = min(temp,a); for (int j = s; j >= w * take; j--){ dp[j] = max(dp[j - w * take] + take * v,dp[j]); } a -= take; temp *= 2; } } } 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...