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 int long long
using namespace std;
int dp[2001]; // first i considered, j space taken
int c[2001];
int v[2001];
int k[2001];
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int s, n; cin >> s >> n;
for(int i=0;i<n;i++){
cin >> v[i] >> c[i] >> k[i];
}
for(int i=0;i<n;i++){
for(int j=s;j>=0;j--){
for(int x=k[i]; x>=1; x--){
if(j+x*c[i] <= s){
dp[j+x*c[i]]=max(dp[j+x*c[i]],dp[j]+v[i]*x);
}
}
}
}
cout << *max_element(dp,dp+s+1) << '\n';
return 0;
}
# | 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... |