• 문제 링크
https://www.acmicpc.net/problem/34635
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int r = read(), g = read(), b = read();
bw.write(String.valueOf(calc(Math.max(0, r - read()), Math.max(0, g - read()), Math.max(0, b - read()), read(), read())));
bw.flush();
}
private static int calc(int r, int g, int b, int rg, int gb) {
if ((r > rg || b > gb) || g > rg - r + gb - b) return -1;
return r + g + b;
}
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' 카테고리의 다른 글
| [백준] 25757 임스와 함께하는 미니게임 - Data Structure / Java (0) | 2025.12.23 |
|---|---|
| [백준] 14184 IOI 2017 Logo - Data Structure / Java (0) | 2025.12.22 |
| [백준] 3211 kino - Greedy / Java (0) | 2025.12.20 |
| [백준] 7274 Liftas - Greedy / Java (0) | 2025.12.19 |
| [백준] 31307 Lines Per Hour - Greedy / Java (0) | 2025.12.18 |
댓글