【題解】Codeforces 1384B2. Koa and the Beach (Hard Version)

【題目敘述】http://codeforces.com/contest/1384/problem/B2

#include <iostream>
using namespace std;
 
int t, n, k, l, a[300005];
 
bool check(int L, int r){
    int b = 0;
    for (int i = L+1; i < r; i++){
        if (l < a[i]) return false;
        int c = k-(l-a[i]), d = k+(l-a[i]);
        if (b+1 > d) return false;
        b = max(b+1, c);
    }
    return true;
}
 
int main() {
    cin >> t;
    while (t--){
        cin >> n >> k >> l;
        for (int i = 1; i <= n; i++){
            cin >> a[i];
        }
        a[n+1] = -1e9;
        n++;
        int last = 0;
        bool flag = true;
        for (int i = 1; i <= n; i++){
            if (a[i]+k <= l){
                if (!check(last, i)){
                    flag = false;
                    break;
                }
                last = i;
            }
        }
        if (flag) cout << "Yes\n";
        else cout << "No\n";
    }
}

分享本文 Share with friends