File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class Main {
6+
7+ public static void main (String [] args ) throws Exception {
8+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
9+ StringTokenizer st;
10+
11+ int n = Integer . parseInt(br. readLine());
12+ int [] arr = new int [n];
13+
14+ st = new StringTokenizer (br. readLine());
15+ for (int i = 0 ; i < n; i++ ) {
16+ arr[i] = Integer . parseInt(st. nextToken());
17+ }
18+
19+ Arrays . sort(arr);
20+
21+ int left = 0 ;
22+ int right = n - 1 ;
23+ int temp = 2000000000 ;
24+ int l = 0 , r = 0 ;
25+
26+ while (left < right) {
27+ int x = arr[left];
28+ int y = arr[right];
29+ int sum = x + y;
30+ if (Math . abs(x + y) < Math . abs(temp)) {
31+ temp = sum;
32+ l = x;
33+ r = y;
34+ }
35+ if (sum > 0 )
36+ right -= 1 ;
37+ else left += 1 ;
38+ }
39+
40+ System . out. println(l + " " + r);
41+ }
42+ }
43+
44+ ```
You can’t perform that action at this time.
0 commit comments