Submission #964548

#TimeUsernameProblemLanguageResultExecution timeMemory
964548KasymKKnapsack (NOI18_knapsack)C++17
73 / 100
1067 ms2880 KiB
#include <bits/stdc++.h> using namespace std; int main(){ int S, n; scanf("%d%d", &S, &n); vector<int> v(n), w(n), k(n); for(int i = 0; i < n; ++i) scanf("%d%d%d", &v[i], &w[i], &k[i]); vector<long long> dp(S + 1); for(int i = 0; i < n; ++i) for(int j = S; j >= w[i]; --j){ int mx = min(j/w[i], k[i]); for(int cnt = 1; cnt <= mx; ++cnt) dp[j] = max(dp[j], dp[j - cnt*w[i]] + cnt*v[i]); } long long ans = *max_element(dp.begin(), dp.end()); printf("%lld\n", ans); return 0; }

Compilation message (stderr)

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