#K60697. Allocate Parcels to Trucks

    ID: 31144 Type: Default 1000ms 256MiB

Allocate Parcels to Trucks

Allocate Parcels to Trucks

You are given n parcels and m trucks. Each truck i has a delivery capacity \(C_i\) and is available to deliver parcels. Each parcel is uniquely identified by its sequence in the input. Your task is to allocate parcels to trucks in order, such that each truck is assigned at most its capacity of parcels and each parcel is assigned to at most one truck. If the total number of parcels exceeds the sum of all truck capacities \(\sum_{i=1}^{m} C_i\), only the first \(\sum_{i=1}^{m} C_i\) parcels (in order) should be assigned.

The allocation should be represented as an m × n matrix \(A\) where:

  • \(A[i][j] = 1\) if the j-th parcel is allocated to the i-th truck.
  • \(A[i][j] = 0\) otherwise.

Follow a greedy strategy: For each truck in order, assign parcels sequentially until its capacity is filled. Then proceed to the next truck.

inputFormat

The input is given via stdin and consists of:

  1. The first line contains two space-separated integers: n (number of parcels) and m (number of trucks).
  2. The second line contains n space-separated integers representing the delivery locations or identifiers of the parcels. (These values are provided for completeness but do not affect allocation.)
  3. The third line contains m space-separated integers representing the capacities of the trucks.

outputFormat

Output the allocation matrix to stdout in m lines. Each line corresponds to one truck and contains n space-separated integers (either 0 or 1) indicating whether the corresponding parcel is assigned to that truck.

## sample
5 3
20 35 50 40 60
2 1 2
1 1 0 0 0

0 0 1 0 0 0 0 0 1 1

</p>