A harbor runs n ferries in parallel. Ferry i takes t[i] whole minutes to complete one crossing and immediately starts another, so within T minutes it completes floor(T / t[i]) crossings. All ferries start at minute 0.
The harbor must reach at least C completed crossings in total across all ferries. Find the fewest whole minutes T needed.
Line 1: two integers n and C.
Line 2: n space-separated integers, the per-crossing times.
A single integer: the minimum number of minutes to reach C total crossings.
Example 1
Input
3 6 1 2 3
Expected
4
Explanation
At 4 minutes the ferries complete 4+2+1 = 7 crossings which meets the target of 6; at 3 minutes they complete only 3+1+1 = 5, so 4 minutes is the fewest.
Example 2
Input
2 5 2 2
Expected
6
Explanation
Both ferries take 2 minutes, so together they finish 2*floor(T/2) crossings; this reaches 5 only at T=6 (2*3 = 6), while T=4 gives just 4.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →