-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFactoryMachines.java
More file actions
40 lines (39 loc) · 1.13 KB
/
FactoryMachines.java
File metadata and controls
40 lines (39 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.io.*;
import java.util.*;
public class FactoryMachines{
public static void main(String []args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s[] = br.readLine().split(" ");
int n = Integer.parseInt(s[0]);
int t = Integer.parseInt(s[1]);
int a[] = new int[n];
String s1[] = br.readLine().split(" ");
int max = Integer.MIN_VALUE;
for(int i = 0; i < n; i++) {
a[i] = Integer.parseInt(s1[i]);
if(max < a[i])
max = a[i];
}
long l = 1l;
long u = (long)Math.pow(10, 18);
long ans = 0l;
while(l <= u) {
long mid = (l + u)/2;
long mpm = 0;
for(int i = 0; i < n; i++) {
mpm += mid / a[i];
if(mpm >= t) {
break;
}
}
if(mpm < t) {
l = mid + 1;
} else {
ans = mid;
u = mid - 1;
}
}
System.out.println(ans);
}
}