Submission #1304109

#TimeUsernameProblemLanguageResultExecution timeMemory
1304109Zone_zoneeKnapsack (NOI18_knapsack)C++20
73 / 100
1097 ms15912 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e5+10, S = 2e4+10; ll dp[S]; pair<ll, ll> a[N*32]; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int s, n; cin >> s >> n; int sz = 0; for(int i = 1; i <= n; ++i){ ll v, w, k; cin >> v >> w >> k; ll took = 1; while(k > 0){ a[sz++] = {w*min(k, took), v*min(k, took)}; k -= min(k, took); took <<= 1; } } for(int j = 0; j < sz; ++j){ for(int i = s; i >= a[j].first; --i){ dp[i] = max(dp[i], dp[i-a[j].first] + a[j].second); } } cout << dp[s] << '\n'; }
#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...