Submission #478943

#TimeUsernameProblemLanguageResultExecution timeMemory
478943zwickyKnapsack (NOI18_knapsack)C++14
12 / 100
2 ms1900 KiB
#include<bits/stdc++.h> #define ll long long int #define pb push_back #define loop(i,a,b) for(ll i=a;i<b;i++) #define cy cout<<"YES\n" #define cn cout<<"NO\n" #define cm cout<<-1<<"\n"; #define vl vector<ll> #define vchar vector<char> #define vvll vector<vector<ll>> #define vvcr vector<vchar> using namespace std; const ll MOD=1e9+7; ll times=0; ll binepow(ll a,ll b,ll mod){ if(b==0){ return 1ll; } ll k=binepow(a,b/2,mod); if(b%2==0){ times+=(k*k)/mod; return (k*k)%mod; } else{ ll zz=(k*a)/mod; ll newo=(k*a)%mod; ll vv=(newo*k)/MOD; times+=(vv+(zz*k)/mod+(zz*k)%MOD); return (((k*a)%mod)*k)%mod; } } //////////////////////////////////////////////////////// void solve(){ ll s,n; cin>>s>>n; vl w(n,0); vl value(n,0); vl items(n,0); loop(i,0,n){ cin>>value[i]>>w[i]>>items[i]; } vvll ans(n+1,vl(s+1,0)); ll final=0; vl count(s+1,0); loop(i,1,n+1){ fill(count.begin(),count.end(),0); loop(j,1,s+1){ ans[i][j]=ans[i-1][j]; if(j-w[i-1]>=0){ if(count[j-w[i-1]]<items[i-1]){ if(ans[i][j]<(ans[i][j-w[i-1]]+value[i-1])){ count[j]=count[j-w[i-1]]+1; ans[i][j]=ans[i][j-w[i-1]]+value[i-1]; } } else{ if(ans[i][j]<(ans[i][j-w[i-1]])){ count[j]=count[j-w[i-1]]; ans[i][j]=ans[i][j-w[i-1]]; } } } final=max(final,ans[i][j]); } } cout<<final<<endl; return; } int main(){ ios::sync_with_stdio(0); cin.tie(0); // freopen(".in","r",stdin); // freopen(".out","w",stdout); solve(); }
#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...