Submission #528305

#TimeUsernameProblemLanguageResultExecution timeMemory
528305theysoldtheworldKnapsack (NOI18_knapsack)C++14
17 / 100
31 ms332 KiB
#include <bits/stdc++.h> using namespace std; struct Item { long long v , w , k; }; int main() { ios::sync_with_stdio(false); cin.tie(0); int S , N; cin >> S >> N; vector<Item> a(N); for (int i = 0 ; i < N ; i++) { cin >> a[i].v >> a[i].w >> a[i].k; } vector<long long> dp(S + 1); vector<bool> Reachable(S + 1); Reachable[0] = true; for (int i = 0 ; i < N ; i++) { for (long long how = 1 ; how <= a[i].k ; how++) { for (long long j = S - a[i].w * how ; j >= 0 ; j--) { if (j + a[i].w * how <= S && Reachable[j]) { Reachable[j + a[i].w * how] = true; dp[j + a[i].w * how] = max(dp[j + a[i].w * how] , dp[j] + 1LL * a[i].v * how); } } } } cout << *max_element(dp.begin(),dp.end()) << '\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...