#include <bits/stdc++.h>
using namespace std;
const int N = 1010, M = 20010;
int q[M]; // s的最大值为20000,v的最小值为1,所以队列里面最多是会有200010个元素的
int n, m;
int f[M], g[M];
int main(){
cin >> n >> m;
for (int i = 1; i <= n; ++ i) {
int v, w, s;
cin >> v >> w >> s;
for (int j = 0; j < v; ++ j) {
int hh = 0, tt = -1;
memcpy(g, f, sizeof f); // 用g[]来保存上一次的更新
for (int k = j; k <= m; k += v) {
if (hh <= tt && q[hh] < k - s * v) ++ hh;
if (hh <= tt) f[k] = max(f[k], g[q[hh]] + (k - q[hh]) / v * w);
while (hh <= tt && g[q[tt]] + (k - q[tt]) / v * w <= g[k]) -- tt;
q[++ tt] = k; // 更新单调的队列
}
}
cout << f[n & 1][m] << "平方厘米";
return 0;
}
cout << f[m] << endl;
return 0;
}
标签:int,题解,cin,崩三,椰子树,MHY1001 From: https://www.cnblogs.com/JiuYe-QAQ/p/18127308