-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJ02016
35 lines (32 loc) · 961 Bytes
/
J02016
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
package withouclass;
import java.util.*;
public class J02016 {
public static boolean check(ArrayList<Long> a, int n){
for(int i=2;i<n;i++){
int j=0,k=i-1;
while(j<k){
if(a.get(j)+a.get(k)==a.get(i)) return true;
if(a.get(j)+a.get(k)>a.get(i)) {
k--;
}
else j++;
}
}
return false;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t= Integer.parseInt(in.nextLine());
while(t-->0){
int n= in.nextInt();
ArrayList<Long> a= new ArrayList<>();
for(int i=0;i<n;i++){
long x= in.nextInt();
a.add(x*x);
}
Collections.sort(a);
if(check(a,n)==true) System.out.println("YES");
else System.out.println("NO");
}
}
}