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 n,k;
cin>>n>>k;
vector<vector<int>>v1;
vector<int>v2;
for(int i=0;i<=k;i++){
int a,b,c;
cin>>a>>b>>c;
v2.push_back(a);
v2.push_back(b);
v2.push_back(c);
v1.push_back(v2);
v2.clear();
}
vector<vector<int>>dp(k+1,vector<int>(n+1,0));
// sort(v1.begin(),v1.end(),greater<vector<int>>());
int max1=0;
for(int i=1;i<=k;i++){
for(int j=1;j<=n;j++){
int cnt=0;
while(j>=cnt*(v1[i-1][1])&&cnt<=v1[i-1][2]){
int op1=cnt*v1[i-1][0]+dp[i-1][j-cnt*v1[i-1][1]];
int op2=dp[i-1][j];
dp[i][j]=max(op1,op2);
// cout<<dp[i][j]<<endl;
max1=max(dp[i][j],max1);
cnt++;
}
// max1=max(dp[i][j],max1);
}
}
// for(int i=1;i<=k;i++){
// for(int j=1;j<=n;j++){
// cout<<dp[i][j]<<" ";
// }
// cout<<endl;
// }
// cout<<endl;
cout<<max1<<endl;
}
# | 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... |