Problem 567
Minimum Time to Complete Trips
Medium · 20 pts · Array, Binary Search
Problem
Bus i needs time[i] minutes to complete one trip, and it can start a new trip right after finishing the previous one. All buses run at the same time, independently. Find the minimum number of minutes after which the buses have completed at least T trips in total. In t minutes bus i completes floor(t / time[i]) trips, and this total only grows with t, so binary search on t between 1 and min(time) × T. The numbers in this problem can be larger than a 32-bit int can hold (about 2.1 × 10^9), so use a 64-bit integer type: long long in C++, long in Java (Python needs nothing special).
Input
The first line contains N and T. The second line contains N integers time[0..N-1].
Output
Print the minimum time needed.
Constraints
1 <= N <= 100000; 1 <= time[i] <= 10^7; 1 <= T <= 10^7
Example input
3 5 1 2 3
Example output
3
Explanation
With times 1 2 3 and T = 5: after 3 minutes the buses have done 3 + 1 + 1 = 5 trips, but after 2 minutes only 2 + 1 + 0 = 3. So the answer is 3.