Submission #963176

#TimeUsernameProblemLanguageResultExecution timeMemory
963176QuanmapneKnapsack (NOI18_knapsack)C++14
100 / 100
52 ms7304 KiB
#include<bits/stdc++.h> #define ll long long #define file "knapsack" using namespace std; const int maxN = 1e5 + 5; int t, n, s; int v[maxN], w[maxN], k[maxN]; ll dp[2005]; vector< pair<int, int> > obj[maxN]; void solve(){ for (int i = 1; i <= s; ++i){ if (obj[i].size() == 0) continue; sort(obj[i].begin(), obj[i].end(), greater< pair<int, int> >()); int id = 0; for (int j = 0; j * i < s; ++j){ if (id >= obj[i].size()) break; for (int f = s; f >= i; --f){ dp[f] = max(dp[f], dp[f - i] + obj[i][id].first); } --obj[i][id].second; if (obj[i][id].second == 0) ++id; } } cout << dp[s]; } signed main(){ // freopen(file".inp", "r", stdin); // freopen(file".out", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(0); t = 1; while (t){ cin >> s >> n; for (int i = 1; i <= n; ++i){ cin >> v[i] >> w[i] >> k[i]; obj[w[i]].push_back({v[i], k[i]}); } solve(); --t; } return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'void solve()':
knapsack.cpp:21:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |             if (id >= obj[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...