This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |