This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// https://oj.uz/problem/view/NOI18_knapsack > p83 e p199
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("03,unroll-loops")
const int MAXS = 2000;
int dp[2][MAXS+1];
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int S, n; cin >> S >> n;
vector<int> v(n);
vector<int> w(n);
vector<int> K(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=1; i<=n; i++) {
for (int P=0; P<=S; P++) {
int to_use = 0;
int to_get = 0;
for (int k=0; k<=K[i-1]; k++) {
if (P>=to_use) {
dp[i&1][P] = max(
dp[i&1][P],
dp[(i&1)^1][P-to_use] + to_get
);
} else break;
to_use += w[i-1];
to_get += v[i-1];
}
}
}
cout << dp[n&1][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... |