THINK FIRST·CODE LATER

← All labs

Choosing the time slice: efficiency vs. response time

Problem

Help the EdgeCampus operations team choose a time slice for an interactive server.

Input: first line n s maxWait — the number of processes taking turns, the context-switch cost in ms and the maximum acceptable wait (ms) before a process runs again. Second line: candidate time slices q (ms).

For each q print q=Q efficiency=E% worstWait=W ms + OK or TOO SLOW, where efficiency = q/(q+s) (two decimals) and worstWait = (n − 1)(q + s) (one decimal); OK means worstWait ≤ maxWait.

Then print Best q: Q (efficiency E%) — the OK candidate with the highest efficiency (the largest OK q) — or Best q: none, and Largest possible q: X ms = maxWait / (n − 1) − s (two decimals; if n = 1 print Largest possible q: unlimited; if the value is ≤ 0 print Largest possible q: impossible).

Input:

12 0.2 100
1 2 5 8 10 20

Output:

q=1 efficiency=83.33% worstWait=13.2 ms OK
q=2 efficiency=90.91% worstWait=24.2 ms OK
q=5 efficiency=96.15% worstWait=57.2 ms OK
q=8 efficiency=97.56% worstWait=90.2 ms OK
q=10 efficiency=98.04% worstWait=112.2 ms TOO SLOW
q=20 efficiency=99.01% worstWait=222.2 ms TOO SLOW
Best q: 8 (efficiency 97.56%)
Largest possible q: 8.89 ms

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.