Submission #1104338

#TimeUsernameProblemLanguageResultExecution timeMemory
1104338thaibeo123Knapsack (NOI18_knapsack)C++14
12 / 100
1 ms336 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define ll long long #define pb push_back const int N = 2005; int s, n; ll dp[N]; vector<pair<int, int>> item[N]; void input() { cin >> s >> n; for (int i = 1; i <= n; ++i) { int v, w, k; cin >> v >> w >> k; item[w].pb({v, k}); } } void solve() { for (int i = 1; i <= s; ++i) { dp[i] = -1e18; } for (int i = 1; i <= 2000; ++i) { sort(item[i].begin(), item[i].end()); int val = 0; for (auto it : item[i]) { int sl = 0; while (sl < it.se && val <= s) { val += i; ++sl; for (int j = s; j >= i; --j) { dp[j] = max(dp[j], dp[j - i] + it.fi); } } if (val > s) break; } } ll ans = 0; for (int i = 1; i <= s; ++i) { ans = max(ans, dp[i]); } cout << ans; } int main() { cin.tie(0)->sync_with_stdio(0); input(); solve(); 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...