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;
typedef long long ll;
typedef pair<int, int> pii;
void solve() {
int s, t;
cin >> s >> t;
vector<pii> items; // {weight, value}
while (t--) {
int v, w, k;
cin >> v >> w >> k;
if (w > s) continue; // Ignore items that can't fit even once
for (int i = 1; i <= k; i *= 2) {
items.push_back({w * i, v * i});
k -= i;
}
if (k > 0) {
items.push_back({w * k, v * k});
}
}
vector<int> dp(s + 1, 0);
for (auto &[weight, value] : items) {
for (int j = s; j >= weight; --j) {
dp[j] = max(dp[j], dp[j - weight] + value);
}
}
cout << dp[s] << "\n";
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
solve();
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... |