• 문제 링크
15008번: Falling Apart
After acquiring a new integer and showing it off to other couples at a cocktail party, Alice and Bob headed home for a good night of sleep. As their integer was quite large, they were forced to carry it together. Then, on the Boole Boulevard, right by the
www.acmicpc.net
• 풀이 코드
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 e = 0, o = 0;
while (n-- > 0) {
if ((n & 1) == 0) e += arr[n];
else o += arr[n];
}
bw.write(e > o ? e + " " + o : o + " " + e);
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' 카테고리의 다른 글
[백준] 1110 더하기 사이클 - Implementation / Java (0) | 2024.03.18 |
---|---|
[백준] 1152 단어의 개수 - Implementation / Java (0) | 2024.03.17 |
[백준] 27951 옷걸이 - Greedy / Java (0) | 2024.03.15 |
[백준] 15600 Boss Battle - Greedy / Java (0) | 2024.03.14 |
[백준] 30236 증가 수열 - Greedy / Java (0) | 2024.03.13 |
댓글