Submission #651830

#TimeUsernameProblemLanguageResultExecution timeMemory
651830ash_gamertableKnapsack (NOI18_knapsack)C++14
73 / 100
1076 ms3972 KiB
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #define ff first #define ss second #define int long long #define pb push_back #define mp make_pair #define pii pair<int,int> #define vi vector<int> #define mii map<int,int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 #define ps(x,y) fixed<<setprecision(y)<<x #define mk(arr,n,type) type *arr=new type[n]; #define w(x) int x; cin>>x; while(x--) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define fastio ios_base::sync_with_stdio(0); cin.tie(0); int32_t main() { fastio; int s,n;cin>>s>>n; vi val(n),wt(n),k(n),prev(s+1,0),cur(s+1,0); for(int i=0;i<n;i++) cin>>val[i]>>wt[i]>>k[i]; // for(int x=1;x<=s;x++) // { // ans[x]=ans[x-1]; // for(int i=0;i<n;i++) // { // int copies=k[i],j=wt[i],y=x,temp=val[i]; // while(copies>0 && y-j>=0) // { // ans[x]=max(ans[x],temp+ans[y-j]); // y-=j; // temp+=val[i]; // copies--; // } // } // cout<<x<<" = "<<ans[x]<<endl; // } for(int i=0;i<n;i++) { for(int x=1;x<=s;x++) { int copies=k[i],j=wt[i],y=x,temp=0; // ans[x]=max(ans[x],ans[x-1]); while(copies>0 && y-wt[i]>=0) { y-=wt[i]; temp+=val[i]; copies--; cur[x]=max(cur[x],temp+prev[y]); } } prev=cur; // cout<<cur[1]<<" * "<<cur[2]<<endl; } cout<<cur[s]<<"\n"; return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int32_t main()':
knapsack.cpp:51:29: warning: unused variable 'j' [-Wunused-variable]
   51 |             int copies=k[i],j=wt[i],y=x,temp=0;
      |                             ^
#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...