LearnPy Hub
← Async Basics problems
Hard

Jobs With a Time Limit

Read a time limit in milliseconds, then lines name delay_ms until END (every delay differs from the limit by at least 40 ms). Run all jobs at the same time; each sleeps for its delay and returns its name. Wrap each in asyncio.wait_for with the limit, catching asyncio.TimeoutError. Print name: done or name: timed out in input order, then the count of finished jobs.

Input

Limit, then lines, then END.

Output

Lines.

Sample 1

Input
100
fast 20
slow 200
mid 50
END
Output
fast: done
slow: timed out
mid: done
2 finished

Sample 2

Input
50
only 10
END
Output
only: done
1 finished
solution.py
Output appears here
Jobs With a Time Limit · Python practice problem · LearnPy Hub