Submission #899964

#TimeUsernameProblemLanguageResultExecution timeMemory
899964KN200711Knapsack (NOI18_knapsack)C++14
100 / 100
48 ms3676 KiB
# include <bits/stdc++.h> # define ll long long # define ld long double # define fi first # define se second # define pll pair<ll, ll> # define pdd pair<ld, ld> # define pii pair<int, int> using namespace std; vector<pii> V[2001]; ll dp[2001]; int main() { int S, N; scanf("%d %d", &S, &N); for(int i=1;i<=N;i++) { int a, b, c; scanf("%d %d %d", &a, &b, &c); V[b].push_back({a, c}); } for(int i=1;i<=S;i++) { sort(V[i].begin(), V[i].end()); int cnt = 0; while(V[i].size() && cnt <= S / i) { pii G = V[i].back(); V[i].back().se--; if(V[i].back().se == 0) V[i].pop_back(); for(int d=S;d>=i;d--) { dp[d] = max(dp[d], dp[d - i] + G.fi); } cnt++; } } ll ans = 0ll; for(int i=0;i<=S;i++) ans = max(ans, dp[i]); printf("%lld\n", ans); return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |  scanf("%d %d", &S, &N);
      |  ~~~~~^~~~~~~~~~~~~~~~~
knapsack.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |   scanf("%d %d %d", &a, &b, &c);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...