Skip to content

Commit 0edf461

Browse files
committed
[20260202] BOJ / G5 / 입국심사 / 김민진
1 parent e38c4c2 commit 0edf461

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
```java
2+
import java.io.*;
3+
import java.util.StringTokenizer;
4+
5+
public class BJ_3079_입국심사 {
6+
7+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
9+
private static StringTokenizer st;
10+
11+
private static int N, M;
12+
private static int min;
13+
private static int[] immigration;
14+
15+
public static void main(String[] args) throws IOException {
16+
init();
17+
sol();
18+
}
19+
20+
private static void init() throws IOException {
21+
st = new StringTokenizer(br.readLine());
22+
N = Integer.parseInt(st.nextToken());
23+
M = Integer.parseInt(st.nextToken());
24+
25+
min = Integer.MAX_VALUE;
26+
immigration = new int[N];
27+
for (int i = 0; i < N; i++) {
28+
immigration[i] = Integer.parseInt(br.readLine());
29+
min = Math.min(min, immigration[i]);
30+
}
31+
}
32+
33+
private static void sol() throws IOException {
34+
long left = 1;
35+
long right = (long) min * M;
36+
while (left < right) {
37+
long mid = left + (right - left) / 2;
38+
39+
if (canUseImmigration(mid)) {
40+
right = mid;
41+
} else {
42+
left = mid + 1;
43+
}
44+
}
45+
bw.write(left + "");
46+
bw.flush();
47+
bw.close();
48+
br.close();
49+
}
50+
51+
private static boolean canUseImmigration(long time) {
52+
long cnt = 0;
53+
for (int t : immigration) {
54+
cnt += time / t;
55+
if (cnt >= M) return true;
56+
}
57+
return cnt >= M;
58+
}
59+
60+
}
61+
```

0 commit comments

Comments
 (0)