Bob's empire

4.4

7 votes
Greedy Algorithms, Algorithms, Basics of Greedy Algorithms, Greedy algorithm
Problem

Bob built an empire with five cities (C1,C2,C3,C4,C5). The only mode of transport in this empire is the train.

  1. One can travel from C1to C2 in one minute. This train can occupy at most A people.
  2. One can travel from C2to C3 in one minute. This train can occupy at most B people.
  3. One can travel from C3to C4 in one minute. This train can occupy at most C people.
  4. One can travel from C4to C5 in one minute. This train can occupy at most D people.

For each of them, a train leaves the city at each integer time (0,1,2,...).

There is a group of N people at C1, and they all want to go to C5.

At least how long does it take for all of them to reach there? You can ignore the time needed to transfer.

Input format

  • The first line contains an integer T denoting the number of test cases.
  • The first line of each test case contains a single integer N.
  • The second line of each test case contains four space-separated integers A,B,C, and D respectively.

Output format

For each test case, print the minimum time required for all of the people to reach C5 (in minutes) in a new line.

Constraints

1T1000001N,A,B,C,D1000000000

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For the first test case, it will take in total 5 minutes to reach C5

In the first three minutes, 2 people will non-stop travel to C4 from C1. Since only 1 person can travel at a time from C4 to C5. Thus, total travel time is 5 minutes.

Editor Image

?