-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathP1782.c
39 lines (39 loc) · 1.04 KB
/
P1782.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "stdio.h"
#include "stdlib.h"
#define N 10004
#define M 6
#define C 10004
long long f[C];
struct qele {
int val;
int idx;
} q[C];
int qh, qt;
int main() {
int n, m, c;
scanf("%d %d %d", &n, &m, &c);
for (int i = 0, v, w, d, j, k, val; i < n; i++) {
scanf("%d %d %d", &v, &w, &d);
for (j = 0; j < v; j++) {
qh = 0, qt = -1;
for (k = 0; k <= (c - j) / v; k++) {
val = f[j + k * v] - k * w;
while (qh <= qt && q[qt].val < val) qt--;
q[++qt] = (struct qele){val, k};
while (qh <= qt && q[qh].idx + d < k) qh++;
f[j + k * v] = q[qh].val + k * w;
}
}
}
for (int i = 0, a, b, cc, j; i < m; i++) {
long long x, val;
scanf("%d %d %d", &a, &b, &cc);
for (j = c; j >= 0; j--)
for (x = 0ll; x <= j; x++) {
val = f[j - x] + a*x*x + b*x + cc;
if (val > f[j]) f[j] = val;
}
}
printf("%lld", f[c]);
exit(0);
}