supercomputer

Problem Statement:

A new supercomputer has been developed in Byteland and a lot of eager scientists are using its resources. The supercomputer has N resources and n[i] resources of each type are currently available. There are M scientists who are running one task each on the supercomputer, and each of these tasks require a set of resources Ri : { r[1], r[2],.... r[N]},where r[i] is the no. of units of resource i that the task requires. Also the ith process currently utilizes set of  resources Oi: { o[1], o[2],  ... o[N]} . Your task is to check if each of these tasks can acquire the required amount of resources. Assume that on acquiring the required amount of resources, the process frees all of them and terminates.

Looks like you have already heard of this problem? Perhaps, you have! So do it.

Input Specification:

The first line of the input is the number of test cases T.

The second line contains the number of resources N .

This will be followed by the units of resources ni for each of the resource types in the third line.

The fourth line contains the number of tasks M.

2*M lines containing the resource requirements of the processes follow.

The first M lines contain the currently held resources for each process i.e. Oi

The rest of the lines contain the required set of resources for each process i.e Ri

Output Specification:

Print “YES” (without quotes)  otherwise print “NO” (without quotes) on a single line for each test case.

Constraints :

0 < T < 100

0 < N*M < 10^4 

0 ≤ ni < 10^9

0 < oi ≤ ri ≤ 10^9

0 ≤ i < MSAMPLE INPUT
2
4
1 4 3 4
2
0 0 2 2
1 2 0 0
1 2 3 4
1 2 5 6
2
3 4
2
3 5
0 1
8 8
2 2

SAMPLE OUTPUT
YES
NO

Source: hackerearth | Difficulty: UNKNOWN_DIFFICULTY


Solutions: