Skip to content

Commit 6a6b1a3

Browse files
authored
Merge pull request #745 from AlgorithmWithGod/suyeun84
[20250826] BOJ / G1 / 놀이 공원 / 김수연
2 parents 2847cee + db629ad commit 6a6b1a3

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
public class boj1561 {
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static StringTokenizer st;
8+
static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
9+
static int nextInt() {return Integer.parseInt(st.nextToken());}
10+
11+
static long N;
12+
static int M, max = 0;
13+
static int[] time;
14+
public static void main(String[] args) throws Exception {
15+
nextLine();
16+
N = nextInt();
17+
M = nextInt();
18+
time = new int[M+1];
19+
nextLine();
20+
for (int i = 1; i <= M; i++) {
21+
time[i] = nextInt();
22+
max = Math.max(max, time[i]);
23+
}
24+
if (N <= M) {
25+
System.out.println(N);
26+
return;
27+
} else {
28+
long t = search();
29+
30+
long cnt = M;
31+
for (int i = 1; i <= M; i++)
32+
cnt += (t - 1) / time[i];
33+
34+
for (int i = 1; i <= M; i++) {
35+
36+
if (t % time[i] == 0)
37+
cnt++;
38+
39+
if (cnt == N) {
40+
System.out.println(i);
41+
return;
42+
}
43+
}
44+
}
45+
}
46+
static long search() {
47+
long start = 0;
48+
long end = N/M * max;
49+
while (start <= end) {
50+
long mid = (start + end) / 2;
51+
long sum = M;
52+
for (int i = 1; i <= M; i++) sum += mid / time[i];
53+
if (sum < N) start = mid + 1;
54+
else end = mid - 1;
55+
}
56+
return start;
57+
}
58+
}
59+
```

0 commit comments

Comments
 (0)