#K15491. Remaining Trees After Deforestation
Remaining Trees After Deforestation
Remaining Trees After Deforestation
You are given an initial number of trees T and a series of deforestation reports over N days. On each day, a certain number of trees, given in an array, is cut down. Your task is to compute the number of trees remaining after all days. Note that if at any point the number of trees becomes zero or negative, the output should be 0.
The remaining trees can be mathematically represented as follows:
$$T_{final} = \max\left(0, T - \sum_{i=1}^{N} L_i\right) $$where \(T\) is the initial number of trees and \(L_i\) is the number of trees cut down on day \(i\).
inputFormat
The input is read from standard input (stdin) and contains two lines. The first line has two integers T and N separated by a space, where T is the initial number of trees and N is the number of days. The second line contains N space-separated integers, representing the number of trees cut each day.
outputFormat
Output the number of trees remaining after all N days as a single integer to standard output (stdout). If at any point the number of trees becomes zero or negative, output 0.
## sample100 4
10 20 30 25
15