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 dbg(a) cerr << #a << ": " << a << "\n"
using ll = long long;
void solve() {
ll s, n; cin >> s >> n;
vector<array<ll, 2>> a;
for (int i = 0; i < n; ++i) {
ll v, w, k; cin >> v >> w >> k;
ll kk = 1;
while (k > 0) {
kk = min(kk, k);
if (kk * w > s) break;
a.push_back({kk * v, kk * w});
k -= kk;
kk *= 2;
}
}
vector<ll> dp(s + 1);
for (auto [v, w]: a) {
for (int i = s - w; i >= 0; --i) {
dp[i + w] = max(dp[i + w], dp[i] + v);
}
}
cout << *max_element(dp.begin(), dp.end()) << "\n";
}
int main(){
ios::sync_with_stdio(0), cin.tie(0);
int tc = 1;
for (int t = 1; t <= tc; ++t) {
solve();
}
}
# | 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... |