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;
int main(){
int s, n;
cin >> s >> n;
vector<int> val(n), wt(n), num(n);
for(int i = 0; i < n; i++){
cin >> val[i] >> wt[i] >> num[i];
}
vector<pair<int, int>> how;
for(int i = 0; i < n; i++){
for(int j = 0; j < min(s / wt[i], num[i]); j++){
how.push_back({val[i], wt[i]});
}
}
int sz = how.size();
int dp[sz + 1][s + 1];
for(int i = 0; i <= sz; i++){
for(int j = 0; j <= s; j++){
if(i == 0 || j == 0){
dp[i][j] = 0;
}
}
}
for(int i = 1; i <= sz; i++){
for(int j = 1; j <= s; j++){
if(how[i - 1].second <= j){
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - how[i - 1].second] + how[i - 1].first);
} else{
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[sz][s] << '\n';
}
# | 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... |