#K10051. Tickets Left After Demand
Tickets Left After Demand
Tickets Left After Demand
In this problem, you are given the initial number of tickets (T) and the number of hours (N). For each hour, there is a ticket demand denoted by (D_i). The tickets decrease as follows:
[ T_i = T_{i-1} - D_i \quad \text{for } 1 \leq i \leq N, ]
If at any point (T_i \leq 0), the tickets are considered to have run out, and the answer is 0. Otherwise, after processing all hours, the remaining tickets, (T_N), are output. Your task is to simulate this process and output the number of tickets left (or 0 if they run out).
inputFormat
The input is provided via standard input (stdin).
The first line contains two space-separated integers: (T) (the initial number of tickets) and (N) (the number of hours).
If (N > 0), the second line contains (N) space-separated integers representing the demands (D_1, D_2, \ldots, D_N).
outputFormat
Output a single integer via standard output (stdout) representing the number of tickets remaining after processing the demands, or 0 if the tickets run out.## sample
100 5
10 20 30 10 15
15