This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//looking for 49 points(subtasks 1 - 3)
#include<bits/stdc++.h>
using namespace std;
//#define int long long
using ll = long long;
using ii = pair <int, int>;
const int maxn = 1e5 + 5, maxk = 15, maxs = 2005, N = 2e8 + 5;
int n, s;
int V[maxn], W[maxn], K[maxs];
int dp[maxs];
main () {
ios::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
freopen("in.txt", "r", stdin);
#endif
cin >> s >> n;
for (int i = 1; i <= n; ++i) {
cin >> V[i] >> W[i] >> K[i];
}
int ans = 0;
if (n == 1) {
int take = s / W[1];
ans = take > K[1] ? K[1] * V[1] : take * V[1];
cout << ans;
return 0;
}
for (int i = 1; i <= n; ++i) {
for (int j = s; j >= W[i]; --j) {
int take = s / W[i];
if (take > K[i]) take = K[i];
for (int k = take; k >= 0; --k) {
dp[j] = max(dp[j], dp[j - W[i] * k] + V[i] * k);
ans = max(ans, dp[j]);
}
}
}
cout << dp[s];
return 0;
}
/*
array bound?
overflow?
print newline after every cases
idea correct?
*/
Compilation message (stderr)
knapsack.cpp:18:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
18 | main () {
| ^~~~
# | 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... |