Submission #900199

#TimeUsernameProblemLanguageResultExecution timeMemory
900199aykhnKnapsack (NOI18_knapsack)C++17
100 / 100
44 ms4992 KiB
#include <bits/stdc++.h> // author: aykhn using namespace std; typedef long long ll; #define all(v) v.begin(), v.end() #define pii pair<int, int> #define mpr make_pair #define eb emplace_back #define pb push_back #define ts to_string #define fi first #define se second #define ins insert #define int ll #define inf 0x3F3F3F3F #define infll 0x3F3F3F3F3F3F3F3FLL #define bpc __builtin_popcount const int MXN = 2e3 + 5; int dp[MXN]; vector<array<int, 2>> a[MXN]; signed main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); int s, n; cin >> s >> n; for (int i = 1; i <= n; i++) { int v, w, k; cin >> v >> w >> k; a[w].pb({v, k}); } for (int i = 1; i <= s; i++) { sort(all(a[i])); int take = s / i; while (take-- && !a[i].empty()) { for (int j = s; j >= i; j--) { dp[j] = max(dp[j], dp[j - i] + a[i].back()[0]); } if (!--a[i].back()[1]) a[i].pop_back(); } } cout << *max_element(dp, dp + MXN) << '\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...