#K81837. Cargo Journey Validation

    ID: 35842 Type: Default 1000ms 256MiB

Cargo Journey Validation

Cargo Journey Validation

You are given an initial cargo amount C and a maximum cargo capacity M. Additionally, a sequence of cargo changes is provided in a list L. As the ship visits a sequence of docks, the cargo is modified by the corresponding amounts in L. After each change, the current cargo must satisfy the inequality \(0 \leq \text{current_cargo} \leq M\). Your task is to determine whether it is possible to complete the journey without the cargo ever dropping below 0 or exceeding the maximum capacity M.

Input: The input is read from standard input. The first line contains two integers C and M separated by a space. The second line contains an integer n representing the number of cargo changes. If n is positive, the third line contains n space-separated integers representing the sequence L of cargo changes.

Output: Print YES if the journey can be completed without violating the cargo constraints, otherwise print NO.

For example, if the input is:

10 100
4
20 -30 10 50

then the output should be:

YES

inputFormat

The input format is as follows:

  • The first line contains two integers C and M where C is the initial cargo and M is the maximum cargo capacity.
  • The second line contains an integer n denoting the number of cargo changes.
  • If n is positive, the third line contains n space-separated integers representing the list of cargo changes.

If n is 0, the third line will be absent.

outputFormat

Print a single string: YES if the ship completes the journey without violating the cargo constraints; otherwise, print NO.

## sample
10 100
4
20 -30 10 50
YES

</p>