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;
long long S, N;
long long dp[2001];
int main() {
cin >> S >> N;
for(int i = 0; i < N; i++) {
// cin >> items[i][0] >> items[i][1] >> items[i][2];
long long V, W, K;
cin >> V >> W >> K;
for(int i = 1; i <= min(S, K) && i*W <= S; i++) dp[S] = max(dp[S], dp[S-W*i] + V*i);
// cout << "starting end val: " << dp[S] << endl;
for(int s = S-1; s >= 1; s--) {
// cout << "s: " << s << "W:" << W << " K: " << K << endl;
// cout << "W*K: " << W*K << endl;
if(W*K <= s) {
// cout << "why: " << dp[s-W*K] << endl;
dp[s] = max(dp[s], dp[s-W*K] + V*K);
}
// cout << "got here" << endl;
}
// cout << "hi2" << endl;
}
cout << dp[S] << endl;
}
/*
2000 1
5 5 1
2000 1
1000 2000 1000000000
*/
# | 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... |