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;
#define ll long long int
#define cy cout<<"YES"<<endl
#define cn cout<<"NO"<<endl
#define repp(i,n,k) for(int i=1;i<=n;i+=k)
#define repo(i,n,k) for(int i=0;i<n;i+=k)
#define pb push_back
using namespace std;
ll t,n;
ll l[100005],e[100005],k[100005];
ll memo[100005][2005];
ll dp(ll idx,ll duit){
if(idx>n) return 0;
if(duit<0) return 0;
if(memo[idx][duit]!=-1) return memo[idx][duit];
ll best=dp(idx+1,duit);
for(int i=1;i<=k[idx];i++){
if(duit>=i*e[idx]){
best=max(best,dp(idx+1,duit-i*e[idx])+i*l[idx]);
} else {
break;
}
}
return memo[idx][duit]=best;
}
int main(){
cin>>t>>n;
repp(i,n,1){
cin>>l[i]>>e[i]>>k[i];
}
memset(memo,-1,sizeof memo);
cout<<dp(1,t);
}
# | 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... |