Submission #1039188

#TimeUsernameProblemLanguageResultExecution timeMemory
1039188DeathIsAweKnapsack (NOI18_knapsack)C++14
73 / 100
168 ms262144 KiB
#include <bits/stdc++.h> using namespace std; int dp[2001][2001]; #define int long long int32_t main() { int s, n, d1, d2, d3; cin >> s >> n; vector<vector<int>> items(2001); vector<vector<int>> unsorted(2001); for (int i=0;i<n;i++) { cin >> d1 >> d2 >> d3; if (d3 > 2000) { d3 = 2000; } for (int i=0;i<d3;i++) { unsorted[d2].push_back(d1); } } for (int i=1;i<2001;i++) { sort(unsorted[i].begin(), unsorted[i].end(), greater<int>()); d1 = 0; for (int j: unsorted[i]) { d1 += j; items[i].push_back(d1); } } //for (int i=0;i<2001;i++) { // if (items[i].size() > 0) { // cout << i << ':'; // for (int j: items[i]) { // cout << j << ' '; // } // cout << '\n'; // } //} for (int i=0;i<2001;i++) { dp[0][i] = 0; dp[i][0] = 0; } for (int i=1;i<s+1;i++) { for (int j=1;j<2001;j++) { d2 = dp[i][j-1]; d1 = 0; while (d1 < items[j].size() && (d1 + 1) * j <= i) { d2 = max(d2, dp[i - ((d1 + 1) * j)][j-1] + items[j][d1]); d1++; } dp[i][j] = d2; } } cout << dp[s][2000]; }

Compilation message (stderr)

knapsack.cpp: In function 'int32_t main()':
knapsack.cpp:47:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |                 while (d1 < items[j].size() && (d1 + 1) * j <= 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...