[ AGC007 D ] Shik and Game

题目

Atcoder

思路

[ AGC007 D ]  Shik and Game
[ AGC007 D ]  Shik and Game

代码

#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;
}
上一篇:windows驱动完整卸载的流程(解决卸载后,重新扫描或重启后,驱动仍然出现的问题)


下一篇:toad for oracle 13 + instantclient_11_2 远程访问oracle数据库