Problem :

https://www.hackerrank.com/challenges/minimum-time-required/problem


My Solution :

#!/usr/bin/env python3


def calc_prod(machines, days):
    prod = 0
    for m in machines:
        prod += days // m
    return prod


def calc_max_days(machines, goal):
    m = max(machines)
    c = machines.count(m)
    max_days = (goal*m) // c
    return max_days + 1


def minTime(machines, goal):
    low, high = 0, calc_max_days(machines, goal)
    while low < high:
        mid = (low + high) // 2
        prod = calc_prod(machines, mid)
        if prod < goal:
            low = mid + 1
        else:
            high = mid
    return high


n, goal = map(int, input().split())
machines = list(map(int, input().rstrip().split()))
ans = minTime(machines, goal)
print(ans)