#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define inf32 ((int)1e9 + 7)
#define inf64 ((long long)1e18 + 7)
#define MASK32(x) (1 << (x))
#define MASK64(x) (1ll << (x))
#define BIT(mask, i) (((mask) >> (i)) & 1)
#define all(a) begin(a), end(a)
#define isz(a) ((int)a.size())
const int N = 5e6 + 1;
struct Item {
long long v;
int w;
} a[N];
long long dp[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, W;
cin >> W >> n;
int m = 0;
for(int i = 1; i <= n; ++i) {
long long v;
int w, k;
cin >> v >> w >> k;
int cnt = 1;
while(cnt * 2 <= k && w * cnt <= W) {
a[++m] = {v * cnt, w * cnt};
cnt <<= 1;
}
cnt >>= 1;
cnt = k - cnt;
a[++m] = {v * cnt, w * cnt};
}
n = m;
for(int i = 1; i <= n; ++i)
for(int w = W; w >= a[i].w; --w) dp[w] = max(dp[w], dp[w - a[i].w] + a[i].v);
cout << dp[W];
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... |