Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 |
Tags
- oracle
- priorityqueue
- SQL
- 자바
- BOJ
- 프로그래머스
- MySQL
- 코딩테스트
- 이분탐색
- DP
- SWEA
- 문제해결
- 건강
- Java
- 운동기록
- BFS
- dfs
- 코테
- greedy
- 알고리즘
- math
- binary search
- 문제풀이
- 시뮬레이션
- COS PRO
- db
- 문자열
- 투포인터
- 러닝일지
- 백준
Archives
- Today
- Total
슈콩
[BOJ] 백준 2473 세 용액 본문
[문제]
https://www.acmicpc.net/problem/2473
[소스 코드]
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));
StringTokenizer st;
int n = Integer.parseInt(br.readLine());
int[] nums = new int[n];
st = new StringTokenizer(br.readLine());
for(int i=0;i<n;i++) {
nums[i] = Integer.parseInt(st.nextToken());
}
Arrays.sort(nums);
long result = Long.MAX_VALUE;
int idxStart =0;
int idxEnd = 0;
int idx = 0;
out:
for(int i=0;i<n-2;i++) {
int start = i+1;
int end = n-1;
while(start<end) {
long sum = (long)nums[i] + nums[start] + nums[end];
if(Math.abs(result)>Math.abs(sum)) {
result = sum;
idx = i;
idxStart = start;
idxEnd = end;
}
if(sum==0) {
break out;
}
else if(sum>0) {
end--;
}
else
start++;
}
}
System.out.println(nums[idx] + " " + nums[idxStart] + " " + nums[idxEnd]);
}
}'Algorithms > Baekjoon' 카테고리의 다른 글
| [BOJ] 백준 15685 드래곤 커브 (0) | 2025.09.23 |
|---|---|
| [BOJ] 백준 2512 예산 (0) | 2025.09.23 |
| [BOJ] 백준 15684 사다리 조작 (0) | 2025.09.23 |
| [BOJ] 백준 15683 감시 (0) | 2025.09.23 |
| [BOJ] 백준 14891 톱니바퀴 (0) | 2025.09.23 |