In a public bath, there is a shower that emits water for T seconds each time the switch is pushed. If the switch is pushed while the shower is already running, it will continue to emit water for T seconds from that moment, resetting the timer. It does not mean that the shower will emit water for an additional T seconds beyond the initial period.
Problem Statement:
Given N people, each defined by the times they push the switch (in seconds) relative to the first push, determine the total time the shower will emit water.
Input Format:
The first line contains an integer T (1 ≤ T ≤ 1000) - the duration (in seconds) the shower emits water when the switch is pushed.
The second line contains an integer N (1 ≤ N ≤ 100) - the number of people pushing the switch.
The third line contains N space-separated integers t_i (0 ≤ t_i ≤ 10000), indicating the seconds after the first push that each of the N people pushes the switch.
Output Format:
Output a single integer representing the total time the shower will emit water in seconds.
Example:
Input:
text
5
3
1 2 9
Output:
text
10
Explanation:
The first person pushes the switch at 0 seconds, and the shower runs until 5 seconds.
The second person pushes the switch at 2 seconds, but since the shower is still on, the shower continues until 7 seconds.
The third person pushes the switch at 9 seconds, which restarts the shower for another 5 seconds, running until 12 seconds.
Total water emission time = 12 seconds - 0 seconds = 12 seconds.
Solution Directory:
Place your solution within the /app/ directory.
Make sure to handle edge cases, such as inputs where the time pushes overlap or when all people push the switch at the same time.
Important: place your implementation at /app/solution.py so the verifier can run it.