题解:CF2102B The Picky Cat

· · 题解

思路

明显,此题的答案只与 a 的绝对值有关。对于任意 a_i(i\neq1),当且仅当 |a_i|>|a_1| 时,a_i 的正负性才能影响 a_1 在 a 中的排名。设满足 |a_i|>|a_1| 的 i 的数量为 c,当 c\ge\lfloor\frac{n-1}{2}\rfloor 时 a_1 才可以成为中位数。

代码

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N=1e5+5;
int a[N];
bool help(){
    int n;
    cin>>n;
    int cnt=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(abs(a[i])>abs(a[1])){
            cnt++;
        }
    }
    if(cnt>=(n-1)/2){
        return true;
    }
    return false;
}
signed main(){
    int t;
    cin>>t;
    while(t--){
        cout<<(help()?"YES":"NO")<<endl;
    }
    return 0;
}