Submission #637626

#TimeUsernameProblemLanguageResultExecution timeMemory
637626Trisanu_DasKnapsack (NOI18_knapsack)C++17
100 / 100
55 ms3660 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int mxS=2000; int n, s, dp[mxS+1]; vector<array<int, 2>> v[mxS+1]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> s >> n; for (int i=0; i<n; ++i) { int a, b, c; cin >> a >> b >> c; v[b].push_back({a, c}); } for (int i=1; i<=s; ++i) { if (v[i].empty()) continue; sort(v[i].rbegin(), v[i].rend()); int x = i; for (array<int, 2> a : v[i]) { if (x > s) break; for (int j = 0; j < a[1] && x<=s; j++, x+=i) for (int k = s; k >= i; k--) dp[k]=max(dp[k], dp[k-i]+a[0]); } } cout << dp[s] << '\n'; }
#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...