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>
using namespace std;
int main() {
int s, n;
cin >> s >> n;
long long int data[n][3], dp[s+1], next[s+1];
for (int x = 0; x < n; x ++){
cin >> data[x][0] >> data[x][1] >> data[x][2];
}
for (int x = 0; x <= s; x ++){
dp[x] = next[x] = 0;
}
for (int a = 0; a < n; a ++){
int c = data[a][0], w = data[a][1], k = data[a][2];
for (int b = 0; b < k; b ++){
for (int x = w; x <= s; x ++){
next[x] = max(max(dp[x], dp[x-w] + c), next[x-1]);
}
for (int x = w; x <= s; x ++){
dp[x] = next[x];
}
}
}
cout << dp[s] << endl;
return 0;
}
# | 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... |