Submission #561535

#TimeUsernameProblemLanguageResultExecution timeMemory
561535OnionEggKnapsack (NOI18_knapsack)C++17
73 / 100
13 ms5176 KiB
#pragma GCC optimize("O3") #include<bits/stdc++.h> #define ll long long #define nmax 505 #define fas ios::sync_with_stdio(0); cout.tie(0); cin.tie(0) #define el "\n" #define fi first #define se second using namespace std; ll n, W, v[50005], w[50005], a[50005], dp[100005], dem; int main() { fas; memset(dp,0, sizeof(dp)); dp[0]=0; cin >> W >> n; for(int i = 1;i <= n;i++) cin >> v[i] >> w[i] >> a[i]; for(int i = n;i >= 1; i--) { while(a[i] > 1) { int dem = 1; while (a[i] > dem) { a[i] -= dem; n++; v[n] = v[i]*dem; w[n] = w[i]*dem; dem*=2; } } } for(int i = 1; i <= n; i++) { for(int j = W; j >= w[i]; j--) dp[j] = max(dp[j], dp[j-w[i]]+v[i]); } cout << dp[W]; }
#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...