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
const int N = 1e5 + 5;
int w[N],v[N],k[N];
vector<int>dp_before(2005,0),dp_cur(2005,0);
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n,s;
cin >> s >> n;
for (int i = 1; i <= n; i++) cin >> v[i] >> w[i] >> k[i];
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= s; j++) {
dp_cur[j] = max(dp_cur[j],dp_before[j]);
for (int z = 1; z <= min(s / w[i],k[i]); z++)
if (j + w[i] * z <= s)
dp_cur[j + w[i] * z] = max(dp_cur[j + w[i] * z],dp_before[j] + v[i] * z);
ans = max(ans,dp_cur[j]);
}
dp_before = dp_cur;
}
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... |