Submission #1107588

#TimeUsernameProblemLanguageResultExecution timeMemory
1107588adkjtKnapsack (NOI18_knapsack)C++14
100 / 100
39 ms5836 KiB
#include<bits/stdc++.h> using namespace std; #define f first #define s second vector<pair<long long,long long>> V[2222]; long long dp[2222]; pair<long long,pair<long long,long long>> a[111111];//v,w,k int main() { ios_base::sync_with_stdio(0); cin.tie(0); int s,n; cin>>s>>n; for(int i=1; i<=n; i++) { cin>>a[i].f>>a[i].s.f>>a[i].s.s; if(a[i].s.f>s) continue; V[a[i].s.f].push_back({-a[i].f,a[i].s.s}); } for(int i=1; i<=s; i++) dp[i]=-1; for(int i=1; i<=s; i++) sort(V[i].begin(),V[i].end()); for(int i=1; i<=s; i++) { if (V[i].empty()) continue; int id=0; for(int j=0;j<s/i;j++) //for(auto x:V[i])//v,k { //re: if(id>=V[i].size()) break; for (int w = s; w - i >= 0; w--) { dp[w] = max(dp[w], dp[w - i] - V[i][id].f); } /*idx--; if(idx>s/i) break;*/ V[i][id].s--; if (V[i][id].s == 0) { id++; continue; } //else goto re; } } long long ans=0; for(int i=1; i<=s; i++) ans=max(ans,dp[i]); cout<<ans; }

Compilation message (stderr)

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