Submission #500278

#TimeUsernameProblemLanguageResultExecution timeMemory
500278MohamedFaresNebiliKnapsack (NOI18_knapsack)C++14
73 / 100
1070 ms2636 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<ll, ll>; using vi = vector<int>; #define ff first #define ss second #define pb push_back #define all(x) x.begin(), x.end() #define lb lower_bound #define ub upper_bound ll s, n; ll v[2 * 100005], w[2 * 100005], k[2 * 100005]; ll dp[2][2005]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> s >> n; for(ll l = 0; l < n; l++) cin >> v[l] >> w[l] >> k[l]; for(int l = 0; l <= s; l++) { for(int j = 1; j <= min(s, k[0]); j++) { if(w[0] * j > l) break; dp[0][l] = v[0] * j; } } int a = 0, b = 1; for(int l = 1; l < n; l++) { swap(a, b); int i = 0; for(int j = 0; j <= min(k[l], s); j++) { for(i = s; w[l] * j <= i; i--) dp[a][i] = max(dp[a][i], dp[b][i - w[l] * j] + v[l] * j); } } ll res = 0; for(int l = 0; l <= s; l++) res = max(res, dp[a][l]); cout << res << "\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...