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;
void solve() {
int n, s;
cin >> s >> n;
vector<int> v(n+1), w(n+1), k(n+1);
for (int i = 1; i <= n; i++) {
cin >> v[i] >> w[i] >> k[i];
}
ll dp[n+1][s+1];
for (int i = 0; i <= s; i++) dp[0][i] = -1e17;
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= s; j++) {
dp[i][j] = -1e17;
for (int cnt = 0; cnt <= k[i]; cnt++) {
if (j - w[i]*cnt < 0) break;
dp[i][j] = max(dp[i][j], dp[i-1][j - w[i]*cnt] + v[i]*cnt);
}
}
}
ll ans = 0;
for (int i = 0; i <= s; i++) ans = max(ans, dp[n][i]);
cout << ans << endl;
}
int main() {
int t = 1;
//cin >> t;
while (t--) 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... |