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;
long long s, n, v[100001], w[100001], k[100001];
long long dp[2001];
bool better, improved;
long long old;
int main() {
cin >> s >> n;
for (int i=0; i<n; i++) {
cin >> v[i] >> w[i] >> k[i];
k[i] = min(k[i], s/w[i]);
}
for (int i=0; i<n; i++) {
better = true;
for (int j=0; j<k[i]; j++) if (better) {
better = false;
for (int we=s; we>=0; we--) {
if (we-w[i] >=0) {
old = dp[we];
dp[we] = max(dp[we], dp[we-w[i]] + v[i]);
if (dp[we] > old) better = true;
}
}
}
}
cout << dp[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... |