Submission #668043

#TimeUsernameProblemLanguageResultExecution timeMemory
668043_martynasKnapsack (NOI18_knapsack)C++11
73 / 100
1090 ms3860 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; void FASTIO() {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const int MXN = 1e5+5; int s, n; ll W[MXN], V[MXN], K[MXN]; ll dp[MXN]; int main() { FASTIO(); cin >> s >> n; for(int i = 0; i < n; i++) { cin >> V[i] >> W[i] >> K[i]; K[i] = min(K[i], (ll)s); } dp[0] = 0; for(int i = 0; i < n; i++) { int w = W[i], v = V[i]; for(int k = 0; k < 11; k++) { if(!K[i]) break; int iterations = (K[i] & (1 << k) ? 1 : 2); for(int c = 0; c < iterations; c++) { for(int j = s; j >= w; j--) { dp[j] = max(dp[j], dp[j-w]+v); } K[i] -= 1 << k; } w *= 2; v *= 2; } } cout << *max_element(dp, dp+s+1) << "\n"; return 0; } /* */
#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...