题目
Atcoder
思路
代码
#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;
}