File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Expand file tree Collapse file tree 1 file changed +45
-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 boj2473 {
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 = Integer . parseInt(st. nextToken());
14+ long [] num = new long [N ];
15+ long answer = Long . MAX_VALUE ;
16+ long [] res = new long [3 ];
17+ nextLine();
18+ for (int i = 0 ; i < N ; i++ ) {
19+ num[i] = Long . parseLong(st. nextToken());
20+ }
21+ Arrays . sort(num);
22+
23+ for (int i = 0 ; i < N ; i++ ) {
24+ int start = i+ 1 ;
25+ int end = N - 1 ;
26+ while (start < end) {
27+ long temp = num[i] + num[start] + num[end];
28+ if (Math . abs(temp) < answer) {
29+ res[0 ] = num[i];
30+ res[1 ] = num[start];
31+ res[2 ] = num[end];
32+ answer = Math . abs(temp);
33+ }
34+ if (temp > 0 ) end-- ;
35+ else if (temp < 0 ) start++ ;
36+ else {
37+ System . out. println(res[0 ]+ " " + res[1 ]+ " " + res[2 ]);
38+ return ;
39+ }
40+ }
41+ }
42+ System . out. println(res[0 ]+ " " + res[1 ]+ " " + res[2 ]);
43+ }
44+ }
45+ ```
You can’t perform that action at this time.
0 commit comments