Bottleneck of a path

A file crosses several links one after another. The slowest link decides the speed.

What to build

A program that finds the bottleneck of a path and the time the file needs at that speed.

Requirements

  • Print the bottleneck rate and which link it is (the first one if there is a tie; links count from 1).
  • Print the time in seconds to send the file at the bottleneck rate, with 2 decimal places (ignore propagation and queueing).

Input

Line 1: the file size in megabytes. Line 2: the link rates in Mbps, in path order.

Output

Three lines: bottleneck R Mbps (R printed with no extra zeros), link K, and time T s.

Constraints

1 to 20 links; every number is positive.

Example

Input:

32
100 4 50

Output:

bottleneck 4 Mbps
link 2
time 64.00 s

Why it works

Data cannot move through the path faster than its slowest link, so the whole transfer runs at that rate. Time is the file size in bits divided by that rate.

Examples

Example 1 · Input
32
100 4 50
Expected output
bottleneck 4 Mbps
link 2
time 64.00 s
Example 2 · Input
10
10 10 10
Expected output
bottleneck 10 Mbps
link 1
time 8.00 s

Prompts inside input() are ignored when checking, so input("n: ") is fine.

Hints

Hint 1

The bottleneck is the smallest rate in the list; min() finds it.

Hint 2

Megabytes times 8 gives megabits; megabits divided by Mbps gives seconds.

Hint 3

To find which link it is, use rates.index(smallest) + 1; index() returns the first one.

Solution

Show one correct solution (try it yourself first)
size = float(input())
rates = [float(x) for x in input().split()]
slowest = min(rates)
print(f"bottleneck {slowest:g} Mbps")
print("link", rates.index(slowest) + 1)
print(f"time {size * 8 / slowest:.2f} s")

▶ Open this solution in the compiler, then press Visualize to watch it run step by step

Lesson: Delay and throughput →