#C6656. Drone Delivery Feasibility

    ID: 50440 Type: Default 1000ms 256MiB

Drone Delivery Feasibility

Drone Delivery Feasibility

You are given a set of drones with specific weight limits and a list of orders each having a weight. Your task is to determine whether it is possible to deliver all orders using the available drones. Each drone can deliver orders as long as its capacity is not exceeded. An order can only be delivered by a drone if the remaining capacity of the drone is greater than or equal to the weight of the order.

The strategy to solve this problem is to sort both the list of drone capacities and the order weights in descending order and then try to assign each order to a drone greedily. Formally, let \( D = [d_1,d_2,\ldots,d_n]\) be the drone capacities (with \( d_1 \ge d_2 \ge \ldots \)) and \( O = [o_1,o_2,\ldots,o_m]\) be the order weights (with \( o_1 \ge o_2 \ge \ldots \)). For each order \( o_i \), if there exists a drone \( d_j \) such that \( d_j \ge o_i \), then assign \( o_i \) to \( d_j \) and reduce \( d_j \) by \( o_i \). Otherwise, output impossible.

If all orders are delivered, output possible. The input and output formats must be strictly followed.

inputFormat

The input is given via standard input (stdin) in the following format:

<d> <o>
<w1> <w2> ... <wd>
<o1> <o2> ... <oo>

Where:

  • d is the number of drones.
  • o is the number of orders.
  • The second line contains d integers representing the weight limits of each drone.
  • The third line contains o integers representing the weights of each order.

outputFormat

Output a single line to standard output (stdout):

possible

If it is possible to deliver all orders according to the constraints, otherwise, output:

impossible
## sample
2 3
100 200
50 75 130
possible