Submission #1113270

#TimeUsernameProblemLanguageResultExecution timeMemory
1113270Yang8onKnapsack (NOI18_knapsack)C++17
100 / 100
45 ms3960 KiB
#include <bits/stdc++.h> #define file "main" #define maxn (int) 2005 #define ll long long #define pii pair<int, int> #define fi(i, a, b) for(int i = a; i <= b; i ++) #define fid(i, a, b) for(int i = a; i >= b; i --) using namespace std; int S, n, N; vector<pii> gr[maxn]; pii a[(int)1e5 + 5]; ll dp[maxn]; main() { // freopen(file".inp", "r", stdin); ios::sync_with_stdio(false); cin.tie(0); cin >> S >> n ; fi(i, 1, n) { int v, w, k; cin >> v >> w >> k ; gr[w].push_back({ v, k }); } fi(i, 1, S) sort(gr[i].begin(), gr[i].end()); fi(i, 1, S) { int mx_sl = S/i; while(gr[i].size() && mx_sl > 0) { int v, k; tie(v, k) = gr[i].back(); gr[i].pop_back(); fi(j, 1, min(mx_sl, k)) a[++N] = { v, i }; mx_sl = max(0, mx_sl - k); } } memset(dp, -0x3f, sizeof dp); dp[0] = 0; fi(i, 1, N) { fid(j, S, a[i].second) { dp[j] = max(dp[j], dp[j - a[i].second] + a[i].first); } } cout << *max_element(dp + 0, dp + S + 1); return 0; }

Compilation message (stderr)

knapsack.cpp:16:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   16 |  main() {
      |  ^~~~
#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...