From d3fe1c782f989438d46c2b439222fe7c56713e89 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Mon, 15 Sep 2025 23:25:21 +0900 Subject: [PATCH] =?UTF-8?q?[20250915]=20PGM=20/=20LV2=20/=20=EA=B3=BC?= =?UTF-8?q?=EC=A0=9C=20=EC=A7=84=ED=96=89=ED=95=98=EA=B8=B0=20/=20?= =?UTF-8?q?=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...04\355\226\211\355\225\230\352\270\260.md" | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 "suyeun84/202509/15 PGM LV2 \352\263\274\354\240\234 \354\247\204\355\226\211\355\225\230\352\270\260.md" diff --git "a/suyeun84/202509/15 PGM LV2 \352\263\274\354\240\234 \354\247\204\355\226\211\355\225\230\352\270\260.md" "b/suyeun84/202509/15 PGM LV2 \352\263\274\354\240\234 \354\247\204\355\226\211\355\225\230\352\270\260.md" new file mode 100644 index 00000000..0705f1c2 --- /dev/null +++ "b/suyeun84/202509/15 PGM LV2 \352\263\274\354\240\234 \354\247\204\355\226\211\355\225\230\352\270\260.md" @@ -0,0 +1,59 @@ +```java +import java.util.*; +class Solution { + static int toInt(String num) {return Integer.parseInt(num);} + public String[] solution(String[][] plans) { + int len = plans.length; + ArrayList answer = new ArrayList<>(); + Stack stack = new Stack<>(); + Arrays.sort(plans, (a, b) -> { + if (a[1].compareTo(b[1]) == 0) return a[2].compareTo(b[2]); + return a[1].compareTo(b[1]); + }); + for (int i = 0; i < len-1; i++) { + String work = plans[i][0]; + int cEndTime = toMinutes(plans[i][1]) + Integer.parseInt(plans[i][2]); + int nStartTime = toMinutes(plans[i + 1][1]); + + if (cEndTime > nStartTime) { + stack.push(new Work(work, cEndTime - nStartTime)); + } else { + int leftTime = nStartTime - cEndTime; + answer.add(work); + while (leftTime > 0 && !stack.isEmpty()) { + Work w = stack.pop(); + if (w.time > leftTime) { + stack.push(new Work(w.work, w.time - leftTime)); + break; + } else if (w.time == leftTime) { + answer.add(w.work); + break; + } else { + leftTime -= w.time; + answer.add(w.work); + } + } + } + } + answer.add(plans[len-1][0]); + while(!stack.isEmpty()) { + answer.add(stack.pop().work); + } + return answer.toArray(new String[0]); + } + + private int toMinutes(String time) { + String[] parts = time.split(":"); + return Integer.parseInt(parts[0]) * 60 + Integer.parseInt(parts[1]); + } + + static class Work { + String work; + int time; + public Work(String work, int time) { + this.work = work; + this.time = time; + } + } +} +```