OJ
[BOJ] 11508 2+1 세일 (JAVA)
P3PP4
2023. 6. 10. 10:00
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);
}
}