-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJ02016_BoBaSoPytago.java
More file actions
42 lines (38 loc) · 1011 Bytes
/
Copy pathJ02016_BoBaSoPytago.java
File metadata and controls
42 lines (38 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.util.*;
import java.io.*;
import java.math.*;
public class J02016_BoBaSoPytago {
public static boolean check(long []a,int n)
{
for(int i = n-1; i>=2;i--)
{
long h = a[i];
int l = 0, r = i-1;
while(l<r)
{
if(a[l]+a[r]==a[i]) return true;
else if(a[l]+a[r]<a[i])
++l;
else if(a[l]+a[r]>a[i]) r--;
}
}
return false;
}
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
int t = sc.nextInt();
sc.nextLine();
while(t-->0)
{
int n = sc.nextInt();
long []a = new long[n];
for(int i = 0 ; i < n; i++){
a[i]= sc.nextLong();
a[i]*=a[i];
}
Arrays.sort(a);
if(check(a,n)) System.out.println("YES");
else System.out.println("NO");
}
}
}