A color box
Practice
4.8 (4 votes)
Algorithms
Basics of greedy algorithms
C++
Greedy algorithms
Problem
65% Success 979 Attempts 10 Points 1s Time Limit 256MB Memory 1024 KB Max Code

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

1T10
1N103
0A[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
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'.
Code Editor

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Submissions
Please login to view your submissions
Similar Problems
Points:10
9 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsC++Greedy Algorithms
Points:10
14 votes
Tags:
Basics of Greedy AlgorithmsGreedy AlgorithmsAlgorithms
Points:10
11 votes
Tags:
Greedy AlgorithmsBasics of Greedy AlgorithmsAlgorithms
Editorial

Login to unlock the editorial