【題解】Codeforces 1350D. Orac and Medians

【題目敘述】http://codeforces.com/contest/1350/problem/D

#include <iostream>
using namespace std;
 
int t, n, k, a[100005];
 
int main() {
    cin >> t;
    while (t--){
        cin >> n >> k;
        bool f1 = false, f2 = false;
        for (int i = 2; i <= n+1; i++){
            cin >> a[i];
        }
        a[n+2] = 0;
        a[n+3] = 0;
        for (int i = 2; i <= n+1; i++){
            if (a[i] == k) f1 = true;
            if (a[i] >= k && (a[i-2] >= a[i] || a[i-1] >= a[i] || a[i] <= a[i+1] || a[i] <= a[i+2])) f2 = true;
        }
        if (f1 && f2) cout << "yes\n";
        else if (n == 1 && f1) cout << "yes\n";
        else cout << "no\n";
    }
}
分享本文 Share with friends