• 문제 링크
https://www.acmicpc.net/problem/24755
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = read();
int[] arr = new int[n];
for (int i = 0; i < n; i++) arr[i] = read();
Arrays.sort(arr);
int m = n / 2 + 1, sum = 0;
while (n-- > m) sum += arr[n];
while (m-- > 0) sum += arr[m] / 2;
bw.write(String.valueOf(sum));
bw.flush();
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 13416 주식 투자 - Implementation / Java (0) | 2025.06.14 |
---|---|
[백준] 3059 등장하지 않는 문자의 합 - Implementation / Java (0) | 2025.06.13 |
[백준] 33520 초코바 만들기 - Greedy / Java (0) | 2025.06.11 |
[백준] 27829 Army Strength - Greedy / Java (0) | 2025.06.10 |
[백준] 27041 Leapcow - Greedy / Java (0) | 2025.06.09 |
댓글