From f7d25dd75a175727446419a294507488c8f39487 Mon Sep 17 00:00:00 2001 From: oncsr Date: Thu, 21 Aug 2025 17:49:34 +0900 Subject: [PATCH] =?UTF-8?q?[20250821]=20PGM=20/=20LV3=20/=20=EA=B4=91?= =?UTF-8?q?=EA=B3=A0=20=EC=82=BD=EC=9E=85=20/=20=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1\352\263\240 \354\202\275\354\236\205.md" | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 "khj20006/202508/21 PGM LV3 \352\264\221\352\263\240 \354\202\275\354\236\205.md" diff --git "a/khj20006/202508/21 PGM LV3 \352\264\221\352\263\240 \354\202\275\354\236\205.md" "b/khj20006/202508/21 PGM LV3 \352\264\221\352\263\240 \354\202\275\354\236\205.md" new file mode 100644 index 00000000..b62e2cd8 --- /dev/null +++ "b/khj20006/202508/21 PGM LV3 \352\264\221\352\263\240 \354\202\275\354\236\205.md" @@ -0,0 +1,53 @@ +```java +class Solution { + public int convertTime(String time) { + String[] args = time.split(":"); + return Integer.parseInt(args[0])*3600 + Integer.parseInt(args[1])*60 + Integer.parseInt(args[2]); + } + + public String solution(String play_time, String adv_time, String[] logs) { + // 1. imos + int N = convertTime(play_time), M = convertTime(adv_time); + long[] arr = new long[N+2]; + for(String log : logs) { + String[] args = log.split("-"); + int start = convertTime(args[0]), end = convertTime(args[1]); + arr[start]++; + arr[end]--; + } + + // 2. find + long s = arr[0]; + long[] b = new long[N+1]; + b[0] = s; + for(int i=1;i<=N;i++) { + s += arr[i]; + b[i] = s + b[i-1]; + } + + int ans = 0; + long max = b[M]; + for(int i=1;i+M-1<=N;i++) if(b[i+M-1]-b[i-1] > max) { + max = b[i+M-1]-b[i-1]; + ans = i; + } + + int hour = ans / 3600; + ans %= 3600; + int minute = ans / 60; + ans %= 60; + int second = ans; + + String result = ""; + if(hour < 10) result += "0"; + result += Integer.toString(hour) + ":"; + if(minute < 10) result += "0"; + result += Integer.toString(minute) + ":"; + if(second < 10) result += "0"; + result += Integer.toString(second); + + return result; + + } +} +```