Submission #1184096

#TimeUsernameProblemLanguageResultExecution timeMemory
1184096sigmalordKnapsack (NOI18_knapsack)C++20
73 / 100
1096 ms8404 KiB
#include <bits/stdc++.h> using namespace std; long long n,s,dp[1000005]; 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] + v); } } 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...