Submission #794178

#TimeUsernameProblemLanguageResultExecution timeMemory
794178Kalpit1810Knapsack (NOI18_knapsack)C++17
12 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n, s; cin >> s >> n; map<int, vector<pair<int, int>>> items; for (int i = 0; i < n; i++) { int a, b, c; cin >> a >> b >> c; items[b].push_back({a, c}); } vector<vector<long long>> dp(items.size()+1, vector<long long>(s + 1, INT64_MIN)); dp[0][0]=0; int at = 1; for (auto p : items) { long long w =p.first; vector<pair<int,int>> item = p.second; sort(item.begin(), item.end(), greater<pair<int, int>>()); for (int i = 1; i < s + 1; i++) { dp[at][i] = dp[at - 1][i]; long long copies = 0; long long type = 0; long long value = 0; long long curr = 0; while ((copies + 1) * w <= i && type < item.size()) { value += item[type].first; copies++; curr++; if(dp[at-1][i-copies*w] != INT64_MIN) { dp[at][i] = max(dp[at][i],dp[at-1][i-copies*w]+value); } if (curr==item[type].second){ curr=0; type++; } } } at++; } cout << *max_element(dp.back().begin(), dp.back().end()); }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:36:50: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |             while ((copies + 1) * w <= i && type < 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...