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;
using ll = long long;
ll dp[2005];
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
for (ll& i : dp) i = -1;
dp[0] = 0;
ll S, N; cin >> S >> N;
for (int i = 0; i < N; ++i) {
ll v, w, k;
cin >> v >> w >> k;
for (ll i = 2004; i >= 0; --i) {
if (dp[i] >= 0) {
ll c = 1; ll j = c * w + i;
while (j <= S && c <= k) {
dp[j] = max(dp[j], dp[i] + c * v);
++c; j += w;
}
}
}
}
ll ans = 0;
for (int i = 0; i <= S; ++i) {
ans = max(ans, dp[i]);
}
cout << ans << '\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... |