評分結果(參考) : AC (17ms, 1.6MB)
#include<bits/stdc++.h>
#define int long long
using namespace std;
string getAns(int n){
map<int, int> cnt;
for(int i=0; i<n; i++){
int num;
cin >> num;
cnt[num]++;
if(cnt[num] >= 3){
cin.ignore(1e18, '\n');
return "YES";
}
}
int edge[] = {-1, -1, -1};
for(auto& c : cnt){
for(int i=0; i<c.second; i++){
edge[0] = edge[1];
edge[1] = edge[2];
edge[2] = c.first;
if(edge[0]!=-1 && edge[0]+edge[1]>edge[2]){
return "YES";
}
}
}
return "NO";
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t, n;
cin >> t;
while(t-- > 0){
cin >> n;
cout << getAns(n) << "\n";
}
return 0;
}