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
void solve() {
int s, n;
cin >> s >> n;
vector<int> dp(s + 1, 0);
for (int i = 0; i < n; ++i) {
int v, w, k;
cin >> v >> w >> k;
// Применение метода разбиения на степени двойки для обработки количества k
for (int b = 1; k > 0; b *= 2) {
int num = min(b, k);
k -= num;
int tv = num * v;
int tw = num * w;
// Обновляем массив dp, итерируя от большого веса к меньшему
for (int j = s; j >= tw; --j) {
dp[j] = max(dp[j], dp[j - tw] + tv);
}
}
}
cout << *max_element(dp.begin(), dp.end()) << '\n';
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
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... |