Submission #844775

#TimeUsernameProblemLanguageResultExecution timeMemory
844775qrnoKnapsack (NOI18_knapsack)C++14
73 / 100
1086 ms18892 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int S, N; cin >> S >> N; vector<pair<int, int>> A; for (int i = 0; i < N; i++) { int v, w, k; cin >> v >> w >> k; for (int cnt = 1; cnt <= k; cnt *= 2) { A.push_back({v*cnt, w*cnt}); k -= cnt; } A.push_back({v*k, w*k}); } vector<int> most(S+1); for (auto [v, w] : A) { for (int s = S; s-w >= 0; s--) { most[s] = max(most[s], most[s-w] + v); } } cout << *max_element(begin(most), end(most)) << '\n'; }

Compilation message (stderr)

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