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 <map>
#include <vector>
#include <queue>
#include <cassert>
#define ll long long
using namespace std;
const int NMAX = 1e5;
const ll INF = 1e18;
const int SMAX = 2000;
int S, n;
int v[NMAX + 1], w[NMAX + 1], k[NMAX + 1];
ll dp[SMAX + 1], answer;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> S >> n;
for(int i = 1; i <= n; i++) {
cin >> v[i] >> w[i] >> k[i];
}
for (int i = 0; i <= S; i++) {
dp[i] = -INF;
}
dp[0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = S; j >= w[i]; j--) {
for (int c = 1; c <= k[i] && j - w[i] * c >= 0; c++) {
if (dp[j - w[i] * c] != -INF) {
dp[j] = max(dp[j], dp[j - w[i] * c] + (ll) v[i] * c);
}
}
}
}
answer = -INF;
for (int j = 0; j <= S; j++) {
answer = max(answer, dp[j]);
}
cout << answer << '\n';
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... |