forked from wotjd4305/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproBinary2.java
More file actions
53 lines (44 loc) · 1.07 KB
/
proBinary2.java
File metadata and controls
53 lines (44 loc) · 1.07 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
41
42
43
44
45
46
47
48
49
50
51
52
53
public class proBinary2 {
public static void main(String[] args) {
int times[] = {7, 10};
int n = 6;
System.out.println(solution(n, times));
}
// 1- 7,14,21,28
// 2- 10, 20
public static long solution(int n, int[] times) {
long left;
long right;
long max = 0;
long mid = 0;
long total =0;
//가장 길게 걸리는 심사대
for(int time : times)
{
if(max < time)
max = time;
}
left =1;
right = (long)n*max;
while(left <= right)
{
total = 0;
mid= (left+right)/2;
for(int time : times)
{
total += (mid/time);
}
//생각보다 숫자가 크다 mid를 줄이자
if(total >= n)
{
right = mid -1;
}
//생각보다 숫자가 작다. mid를 늘리자
else
{
left = mid +1;
}
}
return left;
}
}