← 返回 ramp 的题目列表Package Fitting Feasibility
类型:online_judge
Problem: Determine Whether All Packages Can Fit into Boxes
You are given two integer arrays:
packages: length n, where packages[i] is the size of the i-th package.
boxes: length m, where boxes[j] is the capacity of the j-th box.
Each package must be placed into one box, and each box can contain at most one package. A package with size p can be placed into a box with capacity b if p <= b.
Determine whether it is possible to assign every package to a distinct box such that all packages fit.
Return true or false.
Note: This problem is similar to LeetCode 1889, but you do not need to compute the minimum wasted space. You only need to determine feasibility.
Input Format
n m
packages[0] packages[1] ... packages[n-1]
boxes[0] boxes[1] ... boxes[m-1]
Output Format
true
or
false
Constraints
1 <= n, m <= 2 * 10^5
1 <= packages[i], boxes[j] <= 10^9
Example 1
Input:
3 4
2 3 5
3 5 6 2
Output:
true
Explanation: The packages of sizes 2, 3, 5 can be placed into boxes of capacities 2, 3, 5 respectively.
Example 2
Input:
3 2
2 3 5
5 3
Output:
false
Explanation: There are not enough boxes for all packages.
Example
Input
3 4
2 3 5
3 5 6 2
Output
true