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;
int s, n;
//good: {price, weight, quantity}
int a[100001][3];
long long solve() {
long long dp[s+1];
for (int i=0; i<=s; i++) dp[i] = -1;
dp[0] = 0;
long long res = 0;
for (int i=0; i<n; i++) {
int p = a[i][0], w = a[i][1], q = a[i][2];
for (int j=s; j>=0; j--) {
if (dp[j] == -1) continue;
for (int k=0; k<=q; k++) {
if (1L*j+w*k > s) continue;
dp[j+w*k] = max(dp[j+w*k], dp[j] + p*k);
res = max(res, dp[j+w*k]);
}
}
}
return res;
}
int main() {
cin >> s >> n;
for (int i=0; i<n; i++) {
for (int j=0; j<3; j++) {
cin >> a[i][j];
}
}
cout << solve() << "\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... |