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 futaba ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rio return 0;
#define ll long long
// Fun things are fun. //
ll dp[100005][2005], v[100005], k[100005];
int w[100005];
int main() {
/* freopen(".txt", "r", stdin);
freopen(".txt", "w", stdout); */
futaba
int s, n;
cin >> s >> n;
for(int i = 1; i <= n; i++) cin >> v[i] >> w[i] >> k[i];
for(int i = 1; i <= n; i++) {
for(int j = 0; j <= s; j++) {
dp[i][j] = dp[i - 1][j];
for(int l = 0; l <= k[i]; l++) {
if(j >= (w[i] * l)) dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - (w[i] * l)] + (l * v[i]));
}
}
}
cout << dp[n][s] << '\n';
rio
}
# | 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... |