You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
725 B
31 lines
725 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
|
|
const int N = 1010, M = 20010;
|
|
|
|
int n, m;
|
|
int f[M], g[M];
|
|
int q[M];
|
|
int v, w, s;
|
|
// 一维写法
|
|
int main() {
|
|
cin >> n >> m;
|
|
for (int i = 1; i <= n; i++) {
|
|
memcpy(g, f, sizeof g);
|
|
cin >> v >> w >> s;
|
|
for (int j = 0; j < v; j++) {
|
|
int hh = 0, tt = -1;
|
|
for (int k = j; k <= m; k += v) {
|
|
if (hh <= tt && q[hh] < k - s * v) hh++;
|
|
while (hh <= tt && g[k] >= g[q[tt]] + (k - q[tt]) / v * w) tt--;
|
|
q[++tt] = k;
|
|
|
|
f[k] = max(g[k], g[q[hh]] + (k - q[hh]) / v * w);
|
|
}
|
|
}
|
|
}
|
|
printf("%d\n", f[m]);
|
|
return 0;
|
|
}
|