Submission #1043835

#TimeUsernameProblemLanguageResultExecution timeMemory
1043835vaneaKnapsack (NOI18_knapsack)C++14
100 / 100
40 ms3240 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int s, n; cin >> s >> n; vector<array<ll, 3>> v(n); for(int i = 0; i < n; i++) { cin >> v[i][0] >> v[i][1] >> v[i][2]; } sort(v.rbegin(), v.rend()); vector<array<ll, 2>> a; map<int, int> st; for(auto [v, w, k] : v) { while(st[w]+w <= s && k) { --k; st[w]+=w; a.push_back({v, w}); } } vector<ll> dp(s+1); for(auto [v, w] : a) { for(int x = s-w; x >= 0; x--) { dp[x+w] = max(dp[x+w], dp[x]+v); } } ll ans = 0; for(int i = 0; i <= s; i++) { ans = max(ans, dp[i]); } cout << ans; return 0; }

Compilation message (stderr)

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