ALGORITHM πŸ€–/Baekjoon

λ°±μ€€ - 20044

daxx0ne 2023. 3. 28. 12:23

https://www.acmicpc.net/problem/20044

 

20044번: Project Teams

μž…λ ₯은 ν‘œμ€€μž…λ ₯을 μ‚¬μš©ν•œλ‹€. μž…λ ₯의 첫 번째 ν–‰μ—λŠ” νŒ€ 수λ₯Ό λ‚˜νƒ€λ‚΄λŠ” μ–‘μ˜ μ •μˆ˜ n(1 ≤ n ≤ 5,000)이 μ£Όμ–΄μ§„λ‹€. κ·Έ λ‹€μŒ 행에 학생 si 의 μ½”λ”© μ—­λŸ‰ w(si)λ₯Ό λ‚˜νƒ€λ‚΄λŠ” 2n개의 μ–‘μ˜ μ •μˆ˜κ°€ 곡백으둜

www.acmicpc.net

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[2 * n];
        for (int i = 0; i < arr.length; i++) {
            int w = sc.nextInt();
            arr[i] = w;
        }
        Arrays.sort(arr);
        int s = arr[0] + arr[2 * n - 1];
        for (int j = 0; j < n; j++) {
            int sum = arr[j] + arr[(2 * n - 1) - j];
            if (s > sum){
                s = sum;
            }
        }
        System.out.println(s);
    }
}