#K90582. Send With Retry
Send With Retry
Send With Retry
You are given a simulated network request system. In this problem, you must implement a retry mechanism for sending requests. The system provides a sequence of outcomes for each request attempt. An outcome of 1
indicates a successful request, and 0
indicates a transient error.
Your program will read the maximum number of retries allowed (max_retries). Note that the total number of attempts allowed is given by \(\text{allowed attempts} = max\_retries + 1\). Then, a sequence of responses is provided. Process the responses one by one (up to the allowed number of attempts). If any attempt is successful, print Success
and exit immediately; otherwise, if all permitted attempts fail, print Failed after max retries
.
Note: Input is taken from standard input (stdin) and output is written to standard output (stdout).
inputFormat
The input consists of three lines:
- The first line contains an integer max_retries (0 ≤ max_retries ≤ 105), which denotes the maximum number of retries permitted.
- The second line contains an integer n representing the number of responses provided.
- The third line contains n space-separated integers, each either
0
(failure) or1
(success), representing the outcome of each request attempt.
outputFormat
Output a single line to stdout: Success
if a successful response (1) is encountered within the allowed attempts, or Failed after max retries
if all allowed attempts result in failure.
3
4
1 0 0 0
Success
</p>