ACM ICPC 2017 Warmup Contest 9 L

时间:2023-12-31 21:09:20

L. Sticky Situation

While on summer camp, you are playing a game of hide-and-seek in the forest. You need to designate a “safe zone”, where, if the players manage to sneak there without being detected,they beat the seeker. It is therefore of utmost importance that this zone is well-chosen.

ACM ICPC 2017 Warmup Contest 9 L

You point towards a tree as a suggestion, but your fellow hide-and-seekers are not satisfied. After all, the tree has branches stretching far and wide, and it will be difficult to determine whether a player has reached the safe zone. They want a very specific demarcation for the safe zone. So, you tell them to go and find some sticks, of which you will use three to mark anon-degenerate triangle (i.e. with strictly positive area) next to the tree which will count as the safe zone. After a while they return with a variety of sticks, but you are unsure whether you can actually form a triangle with the available sticks.

Can you write a program that determines whether you can make a triangle with exactly three of the collected sticks?

Input

The first line contains a single integer N , with 3 ≤ N ≤ 20 000, the number of sticks collected. Then follows one line with Npositive integers, each less than 2^{60}2​60​​, the lengths of the sticks which your fellow campers have collected.

Output

Output a single line containing a single word: possible if you can make a non-degenerate triangle with three sticks of the provided lengths, and impossible if you can not.

样例输入1

3
1 1 1

样例输出1

possible

样例输入2

5
3 1 10 5 15

样例输出2

impossible

题目来源

ACM ICPC 2017 Warmup Contest 9

问数组中是否存在3个数组成三角形。

 //2017-10-24
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long using namespace std; const int N = ;
ll arr[N];
int n; int main()
{
while(~scanf("%d", &n)){
for(int i = ; i < n; i++)
scanf("%lld", &arr[i]);
sort(arr, arr+n);
bool ok = false;
for(int i = ; i < n-; i++)
if(arr[i] + arr[i+] > arr[i+]){
ok = true;
break;
}
if(ok)printf("possible\n");
else printf("impossible\n");
} return ;
}