Submission #634506

#TimeUsernameProblemLanguageResultExecution timeMemory
634506TS_2392Knapsack (NOI18_knapsack)C++14
100 / 100
378 ms19544 KiB
#include <bits/stdc++.h> #define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define all(x) (x).begin(),(x).end() #define sqr(x) (x)*(x) #define mp make_pair #define fi first #define se second using namespace std; typedef long long ll; typedef long double ldb; typedef pair<ll,ll> pll; typedef pair<ll,int> pli; typedef pair<int,ll> pil; typedef pair<int,int> pii; typedef pair<double,double> pdd; typedef unsigned long long ull; int s,n,dp[2001][2001],res; vector<pii> w[2001]; int main(){ FAST; cin>>s>>n; for(int i=1;i<=n;++i){ int V,W,K; cin>>V>>W>>K; w[W].push_back(mp(V,K)); } for(int i=1;i<=s;++i){ //cout<<i<<'\n'; sort(w[i].begin(),w[i].end(),greater<pii>()); for(int j=1;j<=s;++j){ int idx=0,cnt=0,Sw=0,Sval=0; vector<pii> a(w[i]); dp[i][j]=dp[i-1][j]; while(cnt<j/i&&idx<w[i].size()){ ++cnt; Sw+=i; Sval+=a[idx].fi; dp[i][j]=max(dp[i][j],dp[i-1][j-Sw]+Sval); a[idx].se--; if(!a[idx].se) ++idx; } //cout<<j<<' '<<dp[i][j]<<'\n'; res=max(res,dp[i][j]); } } cout<<res; return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:34:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |             while(cnt<j/i&&idx<w[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...