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>
#define ll long long
#define fi first
#define sec second
#define pb push_back
#define pqueue priority_queue
#define int long long
#define pii pair<int,int>
#define supercepat ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
using namespace std;
int tc,ans=0,n,t;
int l[100005];
int e[100005];
int k[100005];
int memo[100005][2005];
bool vis[100005][2005];
int dp(int idx,int eg){
if(vis[idx][eg]) return memo[idx][eg];
vis[idx][eg]=1;
if(idx==n+1) return 0;
if(eg==0) return 0;
int temp;
for(int i=0;i<=k[idx];i++){
temp=i*e[idx];
if(temp<=eg){
memo[idx][eg]=max(memo[idx][eg],dp(idx+1,eg-temp)+(l[idx]*i));
}
else break;
}
memo[idx][eg]=max(memo[idx][eg],dp(idx+1,eg));
return memo[idx][eg];
}
main(){
supercepat;
cin>>t>>n;
for(int i=1;i<=n;i++){
cin>>l[i]>>e[i]>>k[i];
}
cout<<dp(1,t)<<endl;
}
Compilation message (stderr)
knapsack.cpp:34:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
34 | main(){
| ^~~~
# | 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... |