A color box

4.8

4 votes
Algorithms, Basics of Greedy Algorithms, C++, Greedy Algorithms
Problem

You are given an array A of N integers where the ith element denotes that Bob has A[i] buckets of color i.

In one move, Bob can pick two buckets with the same color and transform them into a bucket of any other color.

Now, Bob is also given an array B of N integers where the ith element denotes that Bob needs at least B[i] buckets of color i. Find if it is possible for Bob to get the required number of buckets for each color using the specified moves. If possible, print 'Yes' else 'No' without quotes.

Note:

  • 1-based indexing is followed.

Input format

  • The first line contains an integer T denoting the number of test cases. 
  • The first line of each test case contains an integer N.
  • The second line of each test case contains N space-separated integers denoting array A.
  • The third line of each test case contains N space-separated integers denoting array B.

Output format

For each test case, print 'Yes' if it is possible for Bob to get the required number of buckets for each color. Otherwise, print 'No'. Print the output in a new line.

Constraints

1T101N1030A[i],B[i]105

 

Sample Input
2
3
4 4 0
2 1 1
3
5 6 1
2 7 2
Sample Output
Yes
No
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For first test case:

  • Choose two buckets of color 1, and transform it to a bucket of color 3.
  • Now, A=[2,4,1],B=[2,1,1] , thus Bob has required number of buckets for each color.
  • Thus, answer is 'Yes'.

For second test case:

  • It can be proved that Bob can not have enough buckets of color to satisfy the conditions. Thus, answer is 'No'.
Editor Image

?