Submission #708166

#TimeUsernameProblemLanguageResultExecution timeMemory
70816601001000ungKnapsack (NOI18_knapsack)C++14
100 / 100
153 ms35684 KiB
#include <bits/stdc++.h> using namespace std; struct chiso{ int val, weight, quantity; }; chiso a[100005]; vector <int> D[2005]; long long dp[2005][2005]; bool cmp(int x, int y){ return a[x].val > a[y].val; } int main(){ //freopen("a.inp", "r", stdin); freopen("a.out", "w", stdout); int s, n; cin >> s >> n; for (int i = 1; i <= n; i++){ cin >> a[i].val >> a[i].weight >> a[i].quantity; D[a[i].weight].push_back(i); } for (int i = 1; i <= s; i++){ if (!D[i].empty()) sort(D[i].begin(), D[i].end(), cmp); } for (int i = 1; i <= s; i++) { for (int j = 1; j <= s; j++) { if (!D[i].empty()) { dp[i][j] = dp[i - 1][j]; int k = 1, dem = 1, ii = 0; long long sum = 0; while (j - k * i >= 0 && ii < D[i].size()) { sum += a[D[i][ii]].val; dp[i][j] = max(dp[i][j], dp[i - 1][j - k * i] + sum); dem++; k++; if (dem > a[D[i][ii]].quantity) dem = 1, ii++; //cout << i << " " << j << " " << ii << " " << dp[i][j] << endl; } } else dp[i][j] = dp[i - 1][j]; //cout << i << " " << j << " " << dp[i][j] << endl; } } cout << dp[s][s]; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:35:45: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |                 while (j - k * i >= 0 && ii < D[i].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...