-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1253.java
More file actions
50 lines (42 loc) · 1.23 KB
/
1253.java
File metadata and controls
50 lines (42 loc) · 1.23 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
import java.io.*;
import java.util.*;
public class Main{
public static void main(String[] ar5gs) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
long arr[] = new long[n];
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
for(int i = 0; i < n; i++){
arr[i] = Long.parseLong(st.nextToken());
}
Arrays.sort(arr);
int good = 0;
for(int i = 0; i < n; i++){
int left = 0;
int right = n - 1;
long target = arr[i];
while(left < right){
if(left == i){
left++;
continue;
}
if(right == i){
right--;
continue;
}
long sum = arr[left] + arr[right];
if(sum == target){
good++;
break;
}
else if(sum < target){
left++;
}
else{
right--;
}
}
}
System.out.println(good);
}
}