AcWing 133. 蚯蚓(隊列的運用)

傳送門

#include <bits/stdc++.h>

#define int long long
using namespace std;
const int MAXN = 1e5 + 10;
int a[MAXN], n, m, q, u, v, t;
queue<int> q1, q2, q3;

bool Cmp(int a, int b) {
    return a > b;
}

int Cacl(int t) {
    int x = -1, a = -1, b = -1, c = -1;
    if (q1.size()) a = q1.front() + t * q;
    if (q2.size()) b = q2.front() + t * q;
    if (q3.size()) c = q3.front() + t * q;
    x = max(a, max(b, c));
    if (x == a)
        q1.pop();
    else if (x == b)
        q2.pop();
    else if (x == c)
        q3.pop();
    return x;
}

signed main() {
    //freopen("in", "r", stdin);
    ios::sync_with_stdio(false);
    cin >> n >> m >> q >> u >> v >> t;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    sort(a + 1, a + 1 + n, Cmp);
    for (int i = 1; i <= n; i++)
        q1.push(a[i]);
    for (int i = 1; i <= m; i++) {
        int x = Cacl(i - 1);
        if (!(i % t))
            cout << x << " ";
        int now1 = x * u / v;
        int now2 = x - now1;
        q2.push(now1 - i * q);
        q3.push(now2 - i * q);
    }
    cout << endl;
    for (int i = 1;i <= n + m; i++){
        int x = Cacl(m);
        if (!(i % t))
            cout << x << ' ';
    }
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章