After Xiaoteng took a math class, he learned a lot of different shapes, but Xiaoteng‘s favorite triangle is because he likes stable shapes, just like his style.
After the Xiaoxun knew it, he wanted to give a triangle as a gift to Xiaoteng. He originally planned to do one, but he was too tired. So he decided to bring some wooden sticks to Xiaoteng and let Xiaoteng make a triangle himself.
One day, Xiaoxun brought n sticks to Xiaoteng. Xiaoteng wanted to try to use three of them to form a triangle, but the number is too much, Xiaoteng stunned, so he can only ask for your help.
There are mutiple test cases.
Each case starts with a line containing a integer n(1≤n≤5×106) which represent the number of sticks and this is followed by n positive intergers(smaller than 231−1) separated by spaces.
#include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;
int n,a[5000000];
int main() {
while(~scanf("%d",&n)) {
for(int i = 0;i < 2 && i < n;i ++) {
scanf("%d",&a[i]);
}
int flag = 0;
for(int i = 2;i < n;i ++) {
scanf("%d",&a[i]);
if(flag) continue;
if(a[i - 2] > a[i] - a[i - 1]) {
flag = 1;
}
}
puts(flag ? "YES" : "NO");
}
}