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 int long long
int s, n, dp[100005][2005] = {0};
signed main(){
cin >> s >> n;
if(n == 1){
int v, w, k; cin >> v >> w >> k;
if(s / w >= k){
cout << k * v;
}else{
cout << (s / w) * v;
}
return 0;
}
int idx = 0;
for(int x = 1; x <= n; x++){
int v, w, k; cin >> v >> w >> k;
for(int i = idx + 1; i <= idx + k; i++){
// cout << i << " -> ";
for(int j = 1; j <= s; j++){
dp[i][j] = dp[i - 1][j];
if(w <= j){
dp[i][j] = max(dp[i][j], dp[i - 1][j - w] + v);
}
// cout << dp[i][j] << ' ';
}// cout << endl;
}
idx += k;
}
cout << dp[idx][s];
}
# | 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... |