From 29af37f84d7eb44baff38f91e747114331fa5d9a Mon Sep 17 00:00:00 2001 From: MINYOUNG CHO Date: Sat, 7 Sep 2024 17:10:52 +0900 Subject: [PATCH] =?UTF-8?q?=EC=84=B8=20=EC=9A=A9=EC=95=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...354\204\270 \354\232\251\354\225\241.java" | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 "\354\241\260\353\257\274\354\230\201/2473 \354\204\270 \354\232\251\354\225\241.java" diff --git "a/\354\241\260\353\257\274\354\230\201/2473 \354\204\270 \354\232\251\354\225\241.java" "b/\354\241\260\353\257\274\354\230\201/2473 \354\204\270 \354\232\251\354\225\241.java" new file mode 100644 index 0000000..5342253 --- /dev/null +++ "b/\354\241\260\353\257\274\354\230\201/2473 \354\204\270 \354\232\251\354\225\241.java" @@ -0,0 +1,45 @@ +import java.io.*; +import java.util.*; + +public class Main { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int N = Integer.parseInt(br.readLine()); + long[] sol = new long[N]; + StringTokenizer st = new StringTokenizer(br.readLine()); + + for ( int i = 0 ; i < N ; i++ ) + sol[i] = Integer.parseInt(st.nextToken()); + + Arrays.sort(sol); + + long[] res = new long[3]; + long min = Long.MAX_VALUE; + + for ( int i = 0 ; i < N-2 ; i++ ) { + int start = i; + int mid = i+1; + int end = N-1; + while ( mid < end ) { + long sum = sol[start]+sol[mid]+sol[end]; + long temp = Math.abs(sum); + + if ( temp < min ) { + min = temp; + res = new long[]{sol[start], sol[mid], sol[end]}; + } + + if ( temp == 0 ) + break; + + if ( sum > 0 ) + end--; + else + mid++; + } + } + + System.out.println( res[0] + " " + res[1] + " " + res[2] ); + } +} \ No newline at end of file