-
Notifications
You must be signed in to change notification settings - Fork 79
/
MinimumTime.py
47 lines (36 loc) · 1019 Bytes
/
MinimumTime.py
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
#!/bin/python3
import math
import os
import random
import re
import sys
def findItems(machines,temp):
ans = 0
for i in range(len(machines)):
ans += temp // machines[i]
return ans
def BinarySearch(machines,goal,high):
low = 1
while low < high:
mid = (low + high) >> 1
item = findItems(machines,mid)
if item < goal:
low = mid + 1
else:
high = mid
return high
# Complete the minTime function below.
def minTime(machines, goal):
maxval = -sys.maxsize
for i in range(len(machines)):
maxval = max(maxval, machines[i])
return BinarySearch(machines,goal,maxval * goal)
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
nGoal = input().split()
n = int(nGoal[0])
goal = int(nGoal[1])
machines = list(map(int, input().rstrip().split()))
ans = minTime(machines, goal)
fptr.write(str(ans) + '\n')
fptr.close()