Submission #920586

#TimeUsernameProblemLanguageResultExecution timeMemory
920586gustavo_dKnapsack (NOI18_knapsack)C++17
73 / 100
1080 ms2952 KiB
// https://oj.uz/problem/view/NOI18_knapsack > p83 e p199 #include <bits/stdc++.h> using namespace std; #pragma GCC optimize("03,unroll-loops") const int MAXS = 2000; int dp[2][MAXS+1]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int S, n; cin >> S >> n; vector<int> v(n); vector<int> w(n); vector<int> K(n); for (int i=0; i<n; i++) { cin >> v[i] >> w[i] >> K[i]; K[i] = min(K[i], (S/w[i])); } for (int i=1; i<=n; i++) { for (int P=0; P<=S; P++) { int to_use = 0; int to_get = 0; for (int k=0; k<=K[i-1]; k++) { if (P>=to_use) { dp[i&1][P] = max( dp[i&1][P], dp[(i&1)^1][P-to_use] + to_get ); } else break; to_use += w[i-1]; to_get += v[i-1]; } } } cout << dp[n&1][S] << endl; 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...