Submission #871110

#TimeUsernameProblemLanguageResultExecution timeMemory
871110tvladm2009Knapsack (NOI18_knapsack)C++17
100 / 100
55 ms4184 KiB
#include <bits/stdc++.h> using i64 = long long; std::vector<std::pair<int, int>> a[2005]; int dp[2005]; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int s, n; std::cin >> s >> n; for (int i = 1; i <= n; i++) { int v, w, k; std::cin >> v >> w >> k; a[w].emplace_back(std::make_pair(v, k)); } std::vector<int> val, w; for (int step = 1; step <= 2000; step++) { std::sort(a[step].rbegin(), a[step].rend()); int lim = s / step; for (int j = 0; j < a[step].size() && lim > 0; j++) { for (int j2 = 1; j2 <= a[step][j].second && lim > 0; j2++) { val.emplace_back(a[step][j].first); w.emplace_back(step); lim--; } } } for (int i = 0; i < val.size(); i++) { for (int j = s; j >= w[i]; j--) { dp[j] = std::max(dp[j], dp[j - w[i]] + val[i]); } } std::cout << dp[s] << "\n"; return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:23:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         for (int j = 0; j < a[step].size() && lim > 0; j++) {
      |                         ~~^~~~~~~~~~~~~~~~
knapsack.cpp:32:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for (int i = 0; i < val.size(); 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...