Submission #492450

#TimeUsernameProblemLanguageResultExecution timeMemory
492450rocwwKnapsack (NOI18_knapsack)C++14
73 / 100
1087 ms332 KiB
#include<bits/stdc++.h> using namespace std; #define sz(x) (int)x.size() #define pb push_back #define mp make_pair #define ll long long #define lli long long #define mod 1000000007 #define mod2 998244353 #define si size() #define dou double void fast(){ ios_base::sync_with_stdio(false); cin.tie(NULL); } /*void init_code(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif }*/ int main(){ fast(); //init_code(); int s,n; cin>>s>>n; long long cnt[s+5]={0}; long long lol[s+5]={0}; int memo[s+5]={0}; memo[0]=1; for(int i=1;i<=n;i++){ long long int v,w,k; cin>>v>>w>>k; if(k*w<=s){ k=min(s/w+1,k); while(k--){ for(int i=s;i>=0;i--){ if(memo[i]){ if(i+w<=s){ memo[i+w]=1; cnt[i+w]=max(cnt[i]+v,cnt[i+w]); } } } } }else{ lol[w]=max(lol[w],v); } } for(int i=1;i<=s;i++){ for(int j=0;j<=s-i;j++){ cnt[j+i]=max(lol[i]+cnt[j],cnt[j+i]); } } long long ans=0; for(int i=0;i<=s;i++){ ans=max(cnt[i],ans); } cout<<ans<<"\n"; }
#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...