Submission #1023630

#TimeUsernameProblemLanguageResultExecution timeMemory
1023630vjudge1Knapsack (NOI18_knapsack)C++17
17 / 100
2 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define ff first #define ss second #pragma GCC optimize("O3") #pragma GCC target("avx2") const int inf = 1e9; signed main() { int n, s; cin >> s >> n; vector<int> v(n), w(n), k(n); for (int i = 0; i < n; i++) { cin >> v[i] >> w[i] >> k[i]; } vector<int> dp(s + 1, 0); for (int i = 0 ; i < n; i++) { for (int j = s; j > 0; j--) { if (w[i] > j) continue; for (int kk = k[i]; kk > 0; kk--) { if (j - kk * w[i] < 0) { break; } dp[j] = max(dp[j], dp[j - kk * w[i]] + kk * v[i]); } } } int ans = 0; for (int i = 0; i < s + 1; i++) { ans = max(dp[i], ans); } cout << ans; }
#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...