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;
int main(){
int s,n; cin>>s>>n;
vector<vector<int>> items(n);
for (int i=0;i<n;i++){
int x,y,z; cin>>x>>y>>z;
items[i]={x,y,z};
}
vector<int> dp(s+1,-1);
dp[0]=0;
for (auto j: items){
vector<int> cnt(s+1,j[2]); //num remaining of this particular item, take max
for (int i=0; i<s; i++){
if (dp[i]!=-1 and cnt[i]>0 and (i+j[1]<=s)){
if ((dp[i+j[1]]==-1) or (dp[i+j[1]]<(dp[i]+j[0]))){
dp[i+j[1]]=dp[i]+j[0];
cnt[i+j[1]]=cnt[i]-1;
} else if (dp[i+j[1]]==dp[i]+j[0]){
cnt[i+j[1]]=max(cnt[i+j[1]],cnt[i]-1);
}
}
}
}
int ans=0;
for (auto i: dp){
ans=max(ans,i);
}
cout<<ans<<'\n';
}
# | 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... |