Submission #729264

#TimeUsernameProblemLanguageResultExecution timeMemory
729264PVSekharKnapsack (NOI18_knapsack)C++14
0 / 100
3 ms468 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const ll MOD = 1000000007; int main() { #ifndef ONLINE_JUDGE freopen("input.in", "r", stdin); freopen("output.out", "w", stdout); #endif ll n,s; cin>>s>>n; vector<ll> dp(s+1,0); map<ll,vector<pair<ll,ll>>> store; ll v,w,k; for (ll i = 0; i < n; i++) { cin>>v>>w>>k; store[w].push_back({v,k}); } for (auto st:store) { sort(st.second.begin(),st.second.end()); reverse(st.second.begin(),st.second.end()); } vector<pair<int,int>> final_store; ll ind=0,x=0; for (ll i = 1; i <= s; i++) { ind=0; if(store[i].size()==0)continue; for (ll j = 1; j <= (s/i); j++) { if(ind >= store[i].size()) break; if(! store[i][ind].second) ind++; if(ind >= store[i].size()) break; store[i][ind].second--; final_store.push_back({i,store[i][ind].first}); } } for(auto i : final_store){ for(int j = s; j >= i.first; j--) dp[j] = max(dp[j],dp[j-i.first]+i.second); } cout<<dp[s]<<endl; return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:36:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |             if(ind >= store[i].size()) break;
      |                ~~~~^~~~~~~~~~~~~~~~~~
knapsack.cpp:38:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |             if(ind >= store[i].size()) break;
      |                ~~~~^~~~~~~~~~~~~~~~~~
knapsack.cpp:29:14: warning: unused variable 'x' [-Wunused-variable]
   29 |     ll ind=0,x=0;
      |              ^
knapsack.cpp:10:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |         freopen("input.in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:11:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |         freopen("output.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...