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
#define pb push_back
#define ff first
#define ss second
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
const int inf = 1e9;
signed main() {
int n, s;
cin >> s >> n;
vector<int> v(n), w(n), k(n);
for (int i = 0; i < n; i++) {
cin >> v[i] >> w[i] >> k[i];
}
vector<int> dp(s + 1, 0);
for (int i = 0 ; i < n; i++) {
for (int j = s; j > 0; j--) {
if (w[i] > j) continue;
for (int kk = k[i]; kk > 0; kk--) {
if (j - kk * w[i] < 0) {
break;
}
dp[j] = max(dp[j], dp[j - kk * w[i]] + kk * v[i]);
}
}
}
int ans = 0;
for (int i = 0; i < s + 1; i++) {
ans = max(dp[i], ans);
}
cout << ans;
}
# | 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... |