Submission #785615

#TimeUsernameProblemLanguageResultExecution timeMemory
7856150x34cKnapsack (NOI18_knapsack)C++17
100 / 100
104 ms3668 KiB
#include <bits/stdc++.h> #define ll long long #define pii pair<int, int> using namespace std; int main() { int S, N; cin >> S >> N; vector<vector<pii>> wei(S + 1); for (int i = 0; i < N; i++) { int v, w, k; cin >> v >> w >> k; wei[w].push_back({v, k}); } for (int i = 1; i <= S; i++) sort(wei[i].begin(), wei[i].end(), greater<pii>()); vector<ll> dp(S + 1, 0); ll ans = 0; for (int i = 1; i <= S; i++) { int idx = 0; for (int j = 0; j < S / i && idx < wei[i].size(); j++) { for (int k = S; k >= i; k--) { dp[k] = max(dp[k], dp[k - i] + wei[i][idx].first); ans = max(ans, dp[k]); } wei[i][idx].second--; if (wei[i][idx].second == 0) idx++; } } cout << ans << endl; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:29:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         for (int j = 0; j < S / i && idx < wei[i].size(); j++)
      |                                      ~~~~^~~~~~~~~~~~~~~
#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...