Problems > Cover the Demands

Cover the Demands

Difficulty: 1300 3500 ms 128 MB

greedy sorting

Each worker has a capacity (array A) and each task a demand (array B); a worker can take one task with demand ≤ capacity. Can all N tasks be assigned to the N workers?

Input: the first line has N; the second line has the N capacities; the third line has the N demands.

Output: YES or NO.

Constraints:

  • 1 ≤ N ≤ 105
  • |values| ≤ 109

Sample Tests

Input 1
3
3 5 2
2 2 4
Output 1
YES
Input 2
2
1 1
1 2
Output 2
NO

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.