-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJ02016.java
More file actions
52 lines (48 loc) · 1.42 KB
/
J02016.java
File metadata and controls
52 lines (48 loc) · 1.42 KB
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
43
44
45
46
47
48
49
50
51
52
package CODE_PTIT;
import java.util.Scanner;
import java.lang.Math;
import java.util.Arrays;
public class J02016 {
public static int BinaryS(long a[], int l, int r, long x) {
if (l > r) {
return -1;
}
int mid = (l + r) / 2;
if (x == a[mid]) {
return mid;
}
if (x < a[mid]) {
return BinaryS(a, l, mid - 1, x);
}
return BinaryS(a, mid + 1, r, x);
}
public static void main(String[] args) {
Scanner inp = new Scanner(System.in);
int t = inp.nextInt();
while (t-- > 0) {
int n = inp.nextInt();
long a[] = new long[n];
for (int i = 0; i < n; i++) {
long x = inp.nextLong();
a[i] = x * x;
}
Arrays.sort(a);
int ok = 0;
for (int i = 0; i < n - 2; i++) {
// if(a[i] == 0) continue;
for (int j = i + 1; j < n-1; j++) {
if (BinaryS(a, j+1, n - 1, a[i] + a[j]) != -1) {
ok = 1;
System.out.println("YES");
break;
}
}
if(ok == 1) break;
}
if (ok == 0) {
System.out.println("NO");
}
System.out.println();
}
}
}