Submission #914413

#TimeUsernameProblemLanguageResultExecution timeMemory
914413Em1LKnapsack (NOI18_knapsack)C++14
100 / 100
54 ms2928 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using tiii = tuple<int, int, int>; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, s; cin >> s >> n; vector < vector < pii > > val(s + 1); for (int i = 1, v, w, k; i <= n; i++) { cin >> v >> w >> k; val[w].push_back({ v, min(k, s / w) }); } vector < int > dp(s + 1, -1); dp[0] = 0; for (int w = 1; w <= s; w++) { sort(val[w].begin(), val[w].end(), greater < >()); int total = 0; for (auto [v, k] : val[w]) { for (int i = 1; i <= k && total <= s; i++) { for (int cur = s; cur >= w; cur--) if (dp[cur - w] >= 0) dp[cur] = max(dp[cur], dp[cur - w] + v); total += w; } } } cout << *max_element(dp.begin(), dp.end()) << "\n"; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:30:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   30 |         for (auto [v, k] : val[w]) {
      |                   ^
#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...