Submission #598991

#TimeUsernameProblemLanguageResultExecution timeMemory
598991HanksburgerKnapsack (NOI18_knapsack)C++17
100 / 100
61 ms3716 KiB
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > v[2005]; int dp[2005]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int s, n; cin >> s >> n; for (int i=1; i<=n; i++) { int a, b, c; cin >> a >> b >> c; v[b].push_back({a, c}); } for (int i=1; i<=s; i++) { sort(v[i].rbegin(), v[i].rend()); int cnt=s/i; for (int j=0; j<v[i].size(); j++) { while (cnt && (v[i][j].second--)) { for (int k=s; k>=i; k--) dp[k]=max(dp[k], dp[k-i]+v[i][j].first); cnt--; } if (!cnt) break; } } cout << dp[s]; return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:22:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |         for (int j=0; j<v[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...