#K15751. Complete Sequential Activities

    ID: 24426 Type: Default 1000ms 256MiB

Complete Sequential Activities

Complete Sequential Activities

You are given a participant with an initial energy E and a bonus value X (which is not used in the energy computation). The participant must complete N activities in order. Each activity consumes a certain amount of energy. Specifically, for each activity the participant loses a_i units of energy. If at any point their energy becomes negative, the participant cannot complete the activities.

Your task is to determine for every test case whether the participant can complete all the activities without the energy ever dropping below zero.

Important: All formulas are given in \( \LaTeX \) format for clarity. For example, the energy update for the \( i^{th} \) activity is:

[ E = E - a_i ]

If at any stage \( E < 0 \), the answer for that test case is NO; otherwise, it is YES.

inputFormat

The first line contains an integer (T) denoting the number of test cases. Each test case starts with a line containing three integers (E), (X), and (N), where (E) is the initial energy, (X) is an extra parameter (unused in the computation), and (N) is the number of activities. This is followed by (N) lines, each containing two integers (a_i) and (b_i), where (a_i) denotes the energy consumed in the (i^{th}) activity and (b_i) is an additional bonus value (which does not affect the energy level).

outputFormat

For each test case, output a single line containing either "YES" if the participant can complete all the activities without the energy dropping below zero at any moment, or "NO" otherwise.## sample

4
10 5 3
3 2
4 2
3 3
15 8 2
10 5
6 4
8 3 3
7 1
8 3
5 2
1 0 1
0 0
YES

NO NO YES

</p>