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 fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define rep(i, n) for(int i = 0 ; i < n ; i++)
#define all(a) a.begin(), a.end()
// subsoal 1 & 2
int main() {
fast
int s, n; cin>>s>>n;
int v[n+1], w[n+1], k[n+1];
rep(i, n){
cin>>v[i]>>w[i]>>k[i];
}
if(n == 1){
int max = s/w[0];
if(max > k[0]){
cout<<v[0]*k[0];
return 0;
} else{
cout<<v[0]*max;
return 0;
}
} else{
int dp[n+1][s+1];
rep(i, s+1) dp[0][i] = 0;
for(int i = 1 ; i<=n ; i++){
for(int j = 0 ; j<=s ; j++){
if(w[i-1] > j){
dp[i][j] = dp[i-1][j];
} else{
dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i-1]] + v[i-1]);
}
}
}
cout<<dp[n][s];
}
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... |