본문 바로가기

OJ

[BOJ] 11508 2+1 세일 (JAVA)

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

 

11508번: 2+1 세일

KSG 편의점에서는 과일우유, 드링킹요구르트 등의 유제품을 '2+1 세일'하는 행사를 하고 있습니다. KSG 편의점에서 유제품 3개를 한 번에 산다면 그중에서 가장 싼 것은 무료로 지불하고 나머지 두

www.acmicpc.net

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        int[] input = new int[N];
        for (int i = 0; i < N; i++) {
            input[i] = Integer.parseInt(br.readLine());
        } // end of input

        Arrays.sort(input);
        int three = 0;
        int sum = 0;
        for (int i = N - 1; i >= 0; i--) {
            if (++three == 3) three = 0;
            else sum += input[i];
        }

        System.out.print(sum);

    }

}

'OJ' 카테고리의 다른 글

[BOJ] 18115 카드 놓기 (JAVA)  (0) 2023.06.12
[BOJ] 13241 최소공배수 (JAVA)  (0) 2023.06.11
[BOJ] 1773 폭죽쇼 (JAVA)  (0) 2023.06.09
[BOJ] 1735 분수 합 (JAVA)  (0) 2023.06.08
[BOJ] 13164 행복 유치원 (JAVA)  (0) 2023.06.07