File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.util.* ;
3+ import java.io.* ;
4+
5+ public class boj2470 {
6+ static BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
7+ static StringTokenizer st;
8+ static void nextLine () throws Exception {st = new StringTokenizer (br .readLine ());}
9+ static int nextInt() {return Integer . parseInt(st. nextToken());}
10+
11+ public static void main(String [] args) throws Exception {
12+ nextLine();
13+ int N = nextInt();
14+ int [] num = new int [N ];
15+ nextLine();
16+ for (int i = 0 ; i < N ; i++ ) num[i] = nextInt();
17+ Arrays . sort(num);
18+
19+ int check = Integer . MAX_VALUE ;
20+ int answer1 = 0 , answer2 = 0 ;
21+ int low = 0 , high = N - 1 ;
22+
23+ while (low< high) {
24+ int sum = num[low]+ num[high];
25+
26+ if (Math . abs(sum)< check) {
27+ check = Math . abs(sum);
28+ answer1 = num[low];
29+ answer2 = num[high];
30+ }
31+ if (sum < 0 ) low++ ;
32+ else high-- ;
33+ }
34+ System . out. println(answer1+ " " + answer2);
35+ }
36+ }
37+ ```
You can’t perform that action at this time.
0 commit comments