forked from GreatAlgorithm-Study/AlgorithmStudy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYJ_43238.java
More file actions
29 lines (25 loc) · 672 Bytes
/
YJ_43238.java
File metadata and controls
29 lines (25 loc) · 672 Bytes
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
public class YJ_43238 {
public static void main(String[] args) {
int n = 6;
int[] times = {7, 10};
System.out.println(binarySearch(n,times));
}
static long binarySearch(int n, int[] times) {
int length = times.length;
long left = 0;
long right = (long) times[length-1]*n;
while(left<right){
long mid = (left+right)/2;
long count = 0;
for(int time : times){
count += mid/time;
}
if(count>=n){
right = mid;
}else{
left = mid+1;
}
}
return right;
}
}