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;
int main() {
int s, n;
cin >> s >> n;
vector<int64_t> dp(s+1, 0);
vector<pair<int64_t, int64_t>> items;
for (int i = 0; i < n; i++) {
int64_t v, w, k;
cin >> v >> w >> k;
k = min((s / k) + 1, k);
for (int j = 0; j < k; j++) {
items.push_back(make_pair(v, w));
}
}
sort(items.begin(), items.end());
int size = items.size();
for (int i = 0; i < size; i++) {
for (int j = n; j > 0; j--) {
if ((j - items[i].second > -1) && (dp[j - items[i].second] + items[i].first > dp[j])) {
dp[j] = dp[j - items[i].second] + items[i].first;
}
}
}
cout << dp[n] << "\n";
}
# | 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... |