Submission #976180

#TimeUsernameProblemLanguageResultExecution timeMemory
976180IrateKnapsack (NOI18_knapsack)C++17
73 / 100
1090 ms18040 KiB
#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int S, n; cin >> S >> n; vector<pair<long long, int>> v = {{0, 0}}; for(int i = 1;i <= n;++i){ int val, w, k; cin >> val >> w >> k; k = min(k, S / w); for(int j = 0;(1 << j) <= k;++j){ v.push_back({(1LL << j) * val, (1 << j) * w}); k -= (1 << j); } if(k)v.push_back({1LL * k * val, k * w}); } n = (int)v.size() - 1; vector<long long> dp(S + 1, -1e18); dp[0] = 0; for(int i = 1;i <= n;++i){ for(int j = S;j >= 0;--j){ if(j - v[i].second >= 0)dp[j] = max(dp[j], dp[j - v[i].second] + v[i].first); } } long long mx = 0; for(int i = 0;i <= S;++i){ mx = max(mx, dp[i]); } cout << mx << '\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...