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

You are given an array \(A\) of \(N\) integers where the \(i^{th}\) 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 \(i^{th}\) 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

\(1 \le T \le 10 \\ 1 \le N \le 10^3 \\ 0 \le A[i], B[i] \le 10^5\)

 

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:10
14 votes
Tags:
Basics of Greedy AlgorithmsGreedy AlgorithmsAlgorithms
Points:10
9 votes
Tags:
Greedy AlgorithmsAlgorithmsStringBasics of Greedy Algorithms
Points:10
9 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsC++Greedy Algorithms