Submission #395103

#TimeUsernameProblemLanguageResultExecution timeMemory
395103rocks03Knapsack (NOI18_knapsack)C++14
100 / 100
70 ms5192 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int, int> #define pll pair<ll, ll> #define ff first #define ss second #define pb push_back #define SZ(x) ((int)(x).size()) #define all(x) x.begin(), x.end() #define debug(x) cout << #x << ": " << x << " " #define nl cout << "\n" #define rep(i, a, b) for(int i = (a); i < (b); i++) #define per(i, a, b) for(int i = (a); i >= (b); i--) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int MAXN = 1e5+100; int S, N; ll v[MAXN], w[MAXN], k[MAXN], dp[MAXN]; const int MAXS = 2e3+100; vector<pll> g[MAXS]; void solve(){ cin >> S >> N; rep(i, 0, N){ cin >> v[i] >> w[i] >> k[i]; g[w[i]].pb({v[i], k[i]}); } rep(w, 1, S + 1){ sort(all(g[w]), greater<pll>()); ll cnt = S / w; for(auto& [v, k] : g[w]){ k = min(k, cnt); cnt -= k; while(k--){ per(s, S, w){ dp[s] = max(dp[s], dp[s - w] + v); } } if(cnt <= 0) break; } } cout << *max_element(dp, dp + S + 1); } int main(){ ios_base::sync_with_stdio(false), cin.tie(nullptr); solve(); return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'void solve()':
knapsack.cpp:33:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   33 |         for(auto& [v, k] : g[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...