From 120b2c2ee54a8d7b276748ff40879500ec93005c Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Mon, 3 Feb 2025 16:33:08 +0900 Subject: [PATCH] =?UTF-8?q?[20250203]=20BOJ=20/=20=EA=B3=A8=EB=93=9C5=20/?= =?UTF-8?q?=20=EC=8B=9C=EA=B0=84=20=EA=B4=80=EB=A6=AC=20/=20=EA=B9=80?= =?UTF-8?q?=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\352\260\204 \352\264\200\353\246\254.md" | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 "suyeun84/202502/03 BOJ G5 \354\213\234\352\260\204 \352\264\200\353\246\254.md" diff --git "a/suyeun84/202502/03 BOJ G5 \354\213\234\352\260\204 \352\264\200\353\246\254.md" "b/suyeun84/202502/03 BOJ G5 \354\213\234\352\260\204 \352\264\200\353\246\254.md" new file mode 100644 index 00000000..990687e2 --- /dev/null +++ "b/suyeun84/202502/03 BOJ G5 \354\213\234\352\260\204 \352\264\200\353\246\254.md" @@ -0,0 +1,55 @@ +```java +import java.util.*; +import java.io.*; + +class Solution +{ + static Work[] works; + + public static void main(String[] args) throws Exception{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + int N = Integer.parseInt(st.nextToken()); + works = new Work[N]; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + works[i] = new Work(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken())); + } + + Arrays.sort(works, (o1, o2) -> { + if (o1.s != o2.s) return o1.s-o2.s; + return o2.t-o1.t; + }); + + int answer = works[0].s - works[0].t; + while (answer >= 0) { + if (check(answer)) { + System.out.println(answer); + return; + } + answer -= 1; + } + System.out.println(-1); + } + + static boolean check(int start) { + int curr = start; + for (Work w : works) { + if (curr + w.t > w.s) return false; + curr += w.t; + } + return true; + } + + static class Work { + int t; + int s; + public Work(int t, int s) { + this.t = t; + this.s = s; + } + } +} + +```