Submission #955180

#TimeUsernameProblemLanguageResultExecution timeMemory
955180vjudge1Knapsack (NOI18_knapsack)C++17
73 / 100
1060 ms3932 KiB
#include<bits/stdc++.h> using namespace std; void solve(){ int S,N; cin>>S>>N; vector<long long> vs(N+1); vector<long long> ws(N+1); vector<long long> ks(N+1); for(int i=1;i<=N;i++) cin>>vs[i]>>ws[i]>>ks[i]; vector<vector<long long>> dp(2,vector<long long>(S+1)); int cur=1; int last=0; for(int i=1;i<=N;i++){ for(int j=S;j>=0;j--){ int count=0; while(count<=ks[i] && ws[i]*count<=j){ dp[cur][j] = max(dp[cur][j], dp[last][j-count*ws[i]]+vs[i]*count); count++; } } swap(cur,last); } // for(auto x:dp){ // for(auto y:x)cout<<y<<' '; // cout<<'\n'; // } cout<<dp[N%2][S]<<'\n'; } int main(){ ios::sync_with_stdio(false); cin.tie(NULL); int t=1; //cin>>t; while(t--) 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...