Submission #209524

#TimeUsernameProblemLanguageResultExecution timeMemory
209524model_codeKnapsack (NOI18_knapsack)C++14
73 / 100
1101 ms31608 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int N, S, M; ll W[2000000], V[2000000], dp[2005]; int main() { scanf("%d%d", &S, &N); M = 0; ll ans = 0; for (int i = 0; i < N; ++i) { ll v, w, cnt; scanf("%lld%lld%lld", &v, &w, &cnt); cnt = min(cnt, S/w); for (int k = 0; cnt > 0; ++k) { if ((1<<k) >= cnt) { V[M] = v*cnt; W[M] = w*cnt; if (W[M] <= S) ++M; ++M; cnt = 0; } else { V[M] = v*(1<<k); W[M] = w*(1<<k); if (W[M] <= S) ++M; else break; ++M; cnt -= (1<<k); } } } memset(dp, 0, sizeof dp); for (int x = 0; x < M; ++x) { for (ll s = S; s >= W[x]; --s) { dp[s] = max(dp[s], dp[s-W[x]]+V[x]); } } printf("%lld\n", *max_element(dp, dp+S+1)+ans); }

Compilation message (stderr)

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