From db629ad4303c739af7e676d423323592478016c5 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Tue, 26 Aug 2025 14:26:29 +0900 Subject: [PATCH] =?UTF-8?q?[20250826]=20BOJ=20/=20G1=20/=20=EB=86=80?= =?UTF-8?q?=EC=9D=B4=20=EA=B3=B5=EC=9B=90=20/=20=EA=B9=80=EC=88=98?= =?UTF-8?q?=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\235\264 \352\263\265\354\233\220.md" | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 "suyeun84/202508/26 BOJ G1 \353\206\200\354\235\264 \352\263\265\354\233\220.md" diff --git "a/suyeun84/202508/26 BOJ G1 \353\206\200\354\235\264 \352\263\265\354\233\220.md" "b/suyeun84/202508/26 BOJ G1 \353\206\200\354\235\264 \352\263\265\354\233\220.md" new file mode 100644 index 00000000..20e74993 --- /dev/null +++ "b/suyeun84/202508/26 BOJ G1 \353\206\200\354\235\264 \352\263\265\354\233\220.md" @@ -0,0 +1,59 @@ +```java +import java.util.*; +import java.io.*; + +public class boj1561 { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static StringTokenizer st; + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + + static long N; + static int M, max = 0; + static int[] time; + public static void main(String[] args) throws Exception { + nextLine(); + N = nextInt(); + M = nextInt(); + time = new int[M+1]; + nextLine(); + for (int i = 1; i <= M; i++) { + time[i] = nextInt(); + max = Math.max(max, time[i]); + } + if (N <= M) { + System.out.println(N); + return; + } else { + long t = search(); + + long cnt = M; + for (int i = 1; i <= M; i++) + cnt += (t - 1) / time[i]; + + for (int i = 1; i <= M; i++) { + + if (t % time[i] == 0) + cnt++; + + if (cnt == N) { + System.out.println(i); + return; + } + } + } + } + static long search() { + long start = 0; + long end = N/M * max; + while (start <= end) { + long mid = (start + end) / 2; + long sum = M; + for (int i = 1; i <= M; i++) sum += mid / time[i]; + if (sum < N) start = mid + 1; + else end = mid - 1; + } + return start; + } +} +```