Bob's empire
Practice
4.4 (7 votes)
Greedy algorithms
Algorithms
Basics of greedy algorithms
Greedy algorithm
Problem
65% Success 1462 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
Bob built an empire with five cities \((C_1, C_2, C_3, C_4, C_5)\). The only mode of transport in this empire is the train.
- One can travel from \(C_1\)to \(C_2\) in one minute. This train can occupy at most $$A$$ people.
- One can travel from \(C_2\)to \(C_3\) in one minute. This train can occupy at most $$B$$ people.
- One can travel from \(C_3 \)to \(C_4\) in one minute. This train can occupy at most $$C$$ people.
- One can travel from \(C_4\)to \(C_5\) 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 $$C_1$$, and they all want to go to $$C_5$$.
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 $$C_5$$ (in minutes) in a new line.
Constraints
\(1 \le T \le 100000\\ 1 \le N,A,B,C,D \le 1000000000\)
Submissions
Please login to view your submissions
Similar Problems
Points:20
6 votes
Tags:
Basics of Greedy AlgorithmsGreedy AlgorithmsAlgorithmsSorting
Points:20
348 votes
Tags:
EasyGreedy AlgorithmsOpenString Manipulation
Points:30
9 votes
Tags:
MediumAlgorithms
Editorial