Submission #475254

#TimeUsernameProblemLanguageResultExecution timeMemory
475254nohaxjustsofloKnapsack (NOI18_knapsack)C++17
100 / 100
85 ms3948 KiB
#include <bits/stdc++.h> #include <iostream> using namespace std; typedef long long ll; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> order_set; const int mxN = 2005; const int mod = 1e9+7; const int mxlogN = 20; const int mxK = 10; vector<pair<int, int>> a[mxN]; ll sum[mxN]; ll dp[mxN]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int S, n; cin >> S >> n; for(int i = 0; i < n; i++) { int V, W, K; cin >> V >> W >> K; a[W].push_back({V, K}); } vector<pair<int, int>> items; ///W V for(int i = 1; i <= S; i++) { sort(a[i].begin(), a[i].end()); while(sum[i] < S && a[i].size()) { while(sum[i] < S && a[i].back().second) { sum[i] += i; a[i].back().second--; items.push_back({i, a[i].back().first}); } a[i].pop_back(); } } for(int i = 0; i < items.size(); i++) { for(int j = S; j >= items[i].first; j--) { if(items[i].second+dp[j-items[i].first] > dp[j]) { dp[j] = items[i].second+dp[j-items[i].first]; } } } cout << dp[S]; } /** 1 8 1 0 1 1 0 1 1 1 */

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:46:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for(int i = 0; i < items.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...