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 srtl(x)sort((x).begin(),(x).end())
#define srtg(x)sort((x).begin(),(x).end(),greater<>())
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define f first
#define s second
#define pb push_back
#define pii pair<int,int>
#define ins insert
#define vi vector<int>
#define vii vector<pii>
#define viii vector<pair<int,pii>>
int ax[4]={0,1,0,-1};
int ay[4]={1,0,-1,0};
#define int long long
int32_t main(){
ios;
int k,n;
cin>>k>>n;
int a[n][3];
for(int i=0;i<n;i++){
for(int j=0;j<3;j++)cin>>a[i][j];
}
vector<int>dp(k+1,0);
for(int i=0;i<n;i++){
int a0=a[i][0];
int a1=a[i][1];
int a2=a[i][2];
for(int j=k;j>=a1;j--){
dp[j]=max(dp[j],dp[j-a1]+a0);
}
}
cout<<dp[k];
return 0;
}
Compilation message (stderr)
knapsack.cpp: In function 'int32_t main()':
knapsack.cpp:31:7: warning: unused variable 'a2' [-Wunused-variable]
31 | int a2=a[i][2];
| ^~
# | 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... |