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 <iostream>
#include <vector>
using namespace std;
#define ll long long
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, s;
cin >> s >> n;
vector<ll> value(n);
vector<ll> weight(n);
vector<ll> freq(n);
for (int i = 0; i < n; i++){
cin >> value[i] >> weight[i] >> freq[i];
}
ll dp[s+1][n+1];
for (int i = 0; i <= n; i++){
for (int w = 0; w <= s; w++){
if ((i == 0) || (w == 0)){
dp[w][i] = 0;
}else {
dp[w][i] = 0;
for (int r = 0; r <= freq[i-1]; r++){
if (r*weight[i-1] <= w){
dp[w][i] = max(dp[w][i], dp[w-weight[i-1]*r][i-1] + r*value[i-1]);
}else{
break;
}
}
}
}
}
cout << dp[s][n] << endl;
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... |