Skip to content

Commit

Permalink
세 용액
Browse files Browse the repository at this point in the history
  • Loading branch information
mymycse committed Sep 7, 2024
1 parent 5530e11 commit 29af37f
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions 조민영/2473 세 용액.java
Original file line number Diff line number Diff line change
@@ -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] );
}
}

0 comments on commit 29af37f

Please sign in to comment.