• 문제 링크
https://www.acmicpc.net/problem/2545
• 풀이 코드
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));
StringBuilder sb = new StringBuilder();
long t = read();
while (t-- > 0) {
skip();
long[] arr = {read(), read(), read()};
long n = arr[0] + arr[1] + arr[2] - read(), m, k;
Arrays.sort(arr);
n -= m = Math.min(n / 3, arr[0]);
k = Math.min(n / 2, arr[1]);
sb.append(m * k * (n - k)).append("\n");
}
bw.write(sb.toString());
bw.flush();
}
private static long read() throws IOException {
long c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
private static void skip() throws IOException {
while (true) if (System.in.read() == '\n') break;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 5993 Invasion of the Milkweed - Graph Theory / Java (0) | 2024.06.16 |
---|---|
[백준] 10320 Button Bashing - Graph Theory / Java (0) | 2024.06.15 |
[백준] 6123 O Those Fads - Greedy / Java (0) | 2024.06.13 |
[백준] 21557 불꽃놀이 - Greedy / Java (0) | 2024.06.12 |
[백준] 26552 Zero - Greedy / Java (0) | 2024.06.11 |
댓글