Submission #917478

#TimeUsernameProblemLanguageResultExecution timeMemory
917478PieArmyKnapsack (NOI18_knapsack)C++17
29 / 100
2 ms468 KiB
#include <bits/stdc++.h> #define fr first #define sc second #define pb push_back #define endl '\n'; typedef long long ll; const ll inf=2000000000000000005; using namespace std; ll pie(ll army){return (1ll<<army);} ll fpow(ll x,ll y,ll m=0){if(y<0){cout<<"powError";return -1;}if(m)x%=m;ll res=1;while(y>0){if(y&1)res*=x;x*=x;if(m){x%=m;res%=m;}y>>=1;}return res;} void code(){ int k,n;cin>>k>>n; int v2[n],w2[n],cnt2[n]; for(int i=0;i<n;i++)cin>>v2[i]>>w2[i]>>cnt2[i]; int io[n],w[n],v[n],cnt[n];iota(io,io+n,0); sort(io,io+n,[&](const int &x,const int &y){return v2[x]>v2[y];}); for(int i=0;i<n;i++){ w[i]=w2[io[i]]; v[i]=v2[io[i]]; cnt[i]=cnt2[io[i]]; } vector<int>dp(k+1,0); for(int i=0;i<n;i++){ vector<int>dp2(k+1,0); for(int j=0;j<=k;j++){ dp2[j]=max(dp2[j],dp[j]); dp2[j+(min(cnt[i],((k-j)/w[i]))*w[i])]=max(dp2[j+(min(cnt[i],((k-j)/w[i]))*w[i])],dp[j]+(min(cnt[i],(k-j)/w[i])*v[i])); } swap(dp2,dp); } int ans=0; for(int x:dp)ans=max(x,ans); cout<<ans; } int main(){ ios_base::sync_with_stdio(false);cin.tie(NULL); bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);} int t=1; if(!t)cin>>t; while(t--){code();cout<<endl;} return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:39:35: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |     bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);}
      |                            ~~~~~~~^~~~~~~~~~~~~~~~~
knapsack.cpp:39:60: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |     bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".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...