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, sz = 0;
cin >> S >> N;
vector<int>values, weights;
int V, W, K;
if(N == 1){
cin >> V >> W >> K;
int num = S / W;
cout << 1LL * min(num, K) * V;
return 0;
}
for(int i = 0;i < N;++i){
cin >> V >> W >> K;
for(int j = 0;j < K;++j){
values.push_back(V);
weights.push_back(W);
}
sz += K;
}
vector<long long>dp(S + 1, -1e9);
long long mx = 0;
dp[0] = 0;
for(int j = 0;j < sz;++j){
for(int i = S;i >= 0;--i){
if(i - weights[j] >= 0)dp[i] = max(dp[i - weights[j]] + 1LL * values[j], dp[i]);
// cout << j << ", " << i << ": " << dp[i] << '\n';
mx = max(mx, dp[i]);
}
}
cout << mx;
}
# | 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... |