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> values, weights;
for(int i=0; i<N; i++){
int value, weight, freq;
cin >> value >> weight >> freq;
while(freq--){
values.push_back(value);
weights.push_back(weight);
}
}
N = weights.size();
vector<vector<int>> dp(N+1, vector<int>(S+1, 0));
for(int i=1; i<=N; i++){
for(int j=0; j<=S; j++){
dp[i][j] = dp[i-1][j];
int left = j - weights[i-1];
if(left >= 0)
dp[i][j] = max(dp[i][j], dp[i-1][left] + values[i-1]);
}
}
cout << dp[N][S] << endl;
}
# | 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... |