第一个样例wa了 其他都过了 求解
查看原帖
第一个样例wa了 其他都过了 求解
476647
oximi123楼主2021/1/31 11:31
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;

    int q[200010];
    int dp[2][200010];
    int t = 0;
    for (int i = 0; i < n; ++i) {
        int c, w, s;
        cin >> w >> c >> s;
        t ^= 1; // t代表当前的数组 t^1 代表i-1时刻的数组
        for (int j = 0; j < c; ++j) {
            int hh = 0, tt = -1;
            for (int k = j; k <= m; k += c) {
                if (hh <= tt && k - s * c > q[hh]) ++hh; // 最多s+1个元素,超出个数限制则移除队首元素
                if (hh <= tt) dp[t][k] = max(dp[t^1][k], dp[t^1][q[hh]] + (k - q[hh]) / c * w); // 队首肯定是最大的
                while (hh <= tt && dp[t^1][q[tt]] + (k - q[tt]) / c * w <= dp[t ^ 1][k]) --tt; //将k压入队列前,先把所有比它小的出队
                q[++tt] = k;
            }
        }
    }

    cout << dp[t][m] << endl;

    return 0;
}
2021/1/31 11:31
加载中...