Submission #890009

#TimeUsernameProblemLanguageResultExecution timeMemory
890009math_piKnapsack (NOI18_knapsack)C++14
100 / 100
85 ms35412 KiB
#include<bits/stdc++.h> using namespace std; long long dp[2005][2005]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); for(int i=0; i<2005; i++) { for(int j=0; j<2005; j++) { dp[i][j] = -2e9; } } int s, n; cin >> s >> n; map<int, vector<pair<int, int>>> mp; for(int i=0; i<n; i++) { int x, y, z; cin >> x >> y >> z; if(y <= s) { mp[y].push_back({x, z}); } } int toji = 1; dp[0][0] = 0; for(auto &[x, item]: mp) { sort(item.begin(), item.end(), greater<pair<int, int>>()); for(int k=0; k<=s; k++) { dp[toji][k] = dp[toji-1][k]; int c = 0, i = 0, j = 0, val = 0; while((c+1)*1ll*x<=k && i < item.size()) { c++; val += item[i].first; if(dp[toji-1][k-(c*1ll*x)]!=-2e9) { dp[toji][k] = max(dp[toji][k], dp[toji-1][k-c*1ll*x] +val); } j++; if(j==item[i].second) { j=0; i++; } } } toji++; } long long res = 0; for(int i=0; i<=s; i++) { res = max(res, (long long) dp[mp.size()][i]); } cout << res << '\n'; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:24:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   24 |  for(auto &[x, item]: mp) {
      |            ^
knapsack.cpp:29:30: 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 |    while((c+1)*1ll*x<=k && i < item.size()) {
      |                            ~~^~~~~~~~~~~~~
#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...