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 <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int S, N;
cin >> S >> N;
vector<pair<int, int>> A;
A.reserve(2'000 * 11);
for (int i = 0; i < N; i++) {
int v, w, k;
cin >> v >> w >> k;
k = min(k, S);
int cnt = 1;
while (true) {
if (cnt <= k) {
A.push_back({v*cnt, w*cnt});
k -= cnt;
cnt *= 2;
} else {
A.push_back({v*k, w*k});
break;
}
}
}
vector<int> most(S+1);
for (auto [v, w] : A) {
for (int s = S; s-w >= 0; s--) {
most[s] = max(most[s], most[s-w] + v);
}
}
cout << *max_element(begin(most), end(most)) << 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... |