Submission #989553

#TimeUsernameProblemLanguageResultExecution timeMemory
989553matus192Knapsack (NOI18_knapsack)C++14
12 / 100
8 ms348 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll signed main() { int s, n; cin >> s >> n; vector<vector<pair<int, int>>> items(2002); for (int i = 0; i < n; i++) { int val, w, amount; cin >> val >> w >> amount; items[w].push_back({val, amount}); } for (auto vec : items) { sort(vec.begin(), vec.end(), greater<pair<int, int>>()); } vector<int> prv(s + 1, 0), akt(s + 1, 0); for (int item = 1; item < items.size(); item++) { for (int weight = 0; weight <= s; weight++) { int val = 0, w = 0, num = 0, amo = 1; while (amo <= s / item) { if (items[item].size() <= num) break; if (amo > items[item][num].second) { amo = 1; num++; if (items[item].size() <= num) break; } val += items[item][num].first; w += item; amo++; if (weight < w) break; akt[weight] = max(akt[weight], val + prv[weight - w]); } } prv = akt; } cout << akt[s] << '\n'; return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:21:29: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for (int item = 1; item < items.size(); item++) {
      |                        ~~~~~^~~~~~~~~~~~~~
knapsack.cpp:26:40: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   26 |                 if (items[item].size() <= num) break;
      |                     ~~~~~~~~~~~~~~~~~~~^~~~~~
knapsack.cpp:30:44: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   30 |                     if (items[item].size() <= num) break;
      |                         ~~~~~~~~~~~~~~~~~~~^~~~~~
#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...