[ AGC007 D ] Shik and Game

题目

Atcoder

思路

007D01.png
007D02.png

代码

#include <iostream>
#include <algorithm>
#include <cstring>
#define int long long
using namespace std;
const int N = 200010;
int n, E, T, q[N], a[N], f[N];
signed main() {
    cin >> n >> E >> T;
    for (int i = 1; i <= n; i++) cin >> a[i];
    int hh = 0, tt = -1, k = 2e9;
    q[++tt] = 0;
    for (int i = 1; i <= n; i++) {
        // 不满足条件就踢出队列, 顺便更新情况2
        while (hh <= tt && 2 * (a[i] - a[q[hh] + 1]) > T) 
            k = min(k, f[q[hh]] - 2 * a[q[hh] + 1]), hh++;
        f[i] = min(f[q[hh]] + T, k + 2 * a[i]), q[++tt] = i;
    }
    cout << f[n] + E << endl;
    return 0;
}
posted @ 2021-05-29 12:44  Protein_lzl  阅读(37)  评论(0编辑  收藏  举报