-
[백준] 2467 용액ALGORITHM/BOJ 2021. 11. 2. 22:34
https://www.acmicpc.net/problem/2467
2021-10-08
123456789101112131415161718192021222324252627282930313233import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.StringTokenizer;public class Main2467 {public static void main(String[] args) throws IOException {BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));StringTokenizer st = new StringTokenizer(bf.readLine().trim());int N = Integer.parseInt(st.nextToken());int[] arr = new int[N];st = new StringTokenizer(bf.readLine());for(int i = 0; i < N; i++) arr[i] = Integer.parseInt(st.nextToken());int[] answer = new int[2];int number = 2000000000;int start = 0;int end = arr.length - 1;while(start < end) {int abs = Math.abs(arr[start] + arr[end]);if(number > abs){answer[0] = arr[start];answer[1] = arr[end];number = abs;}if(arr[start] + arr[end] > 0) end--;else start++;}System.out.println(answer[0] + " " + answer[1]);}}cs #문제풀이
투포인터 알고리즘
'ALGORITHM > BOJ' 카테고리의 다른 글
[백준]1316 그룹 단어 체커 (0) 2021.11.08 [백준] 2941 크로아티아 알파벳 (0) 2021.11.08 [백준] 1913 달팽이 (0) 2021.09.29 [백준] 10816 숫자 카드 2 (0) 2021.09.29 [백준] 1992 쿼드트리 (0) 2021.09.29