#C9394. Package Distribution Problem

    ID: 53482 Type: Default 1000ms 256MiB

Package Distribution Problem

Package Distribution Problem

You are given M vehicles and N packages. Each vehicle has a maximum weight capacity and each package has a weight. The task is to determine whether it is possible to distribute all packages among the vehicles such that the total weight assigned to any vehicle does not exceed its capacity.

In other words, for a vehicle with capacity \(C_i\) and a set of packages with weights \(w_1, w_2, \dots, w_k\) assigned to it, the following must hold:

[ \sum_{j=1}^{k} w_j \leq C_i ]

A greedy approach is recommended: first, sort the vehicles and packages in descending order, then for each package, try to assign it to the vehicle with the highest remaining capacity that can accommodate it. If every package can be assigned successfully, output "YES"; otherwise, output "NO".

inputFormat

The input is read from stdin and has the following format:

  • The first line contains two integers M and N separated by a space, where M is the number of vehicles and N is the number of packages.
  • The second line contains M integers, representing the capacities of the vehicles.
  • The third line contains N integers, representing the weights of the packages.

outputFormat

The output is printed to stdout. Print "YES" if it is possible to assign all packages to the vehicles without exceeding any vehicle's capacity. Otherwise, print "NO".

## sample
3 6
50 70 80
20 30 40 35 25 15
YES