#K6456. Maximize Single Service Allocation

    ID: 32002 Type: Default 1000ms 256MiB

Maximize Single Service Allocation

Maximize Single Service Allocation

You are given a number of districts, a list of integers representing the number of residential buildings in each district, and a number of available services. Your task is to distribute the available services to the districts such that the maximum number of districts receive exactly one service. Note that any surplus services after giving each district one service are not allocated.

Formally, let (D) be the number of districts and (S) be the available services. The goal is to allocate one service to as many districts as possible, i.e. the maximum number of districts that can receive exactly one service is (\min(D,S)). The distribution plan is represented as a list of (D) integers where each integer is 1 if a district receives a service, and 0 otherwise.

inputFormat

The input is read from standard input (stdin) and it consists of three lines:

  1. The first line contains a single integer (D) representing the number of districts.
  2. The second line contains (D) space-separated integers representing the number of residential buildings in each district (this information is not used for allocation but is provided as part of the input).
  3. The third line contains a single integer (S) representing the number of available services.

outputFormat

The output is written to standard output (stdout) and consists of two lines:

  1. The first line contains a single integer representing the maximum number of districts that receive exactly one service.
  2. The second line contains (D) space-separated integers, where each integer is either 1 (if the district is allocated a service) or 0 (if not). The first (\min(D,S)) districts are allocated service 1, and the rest are 0.## sample
5
10 20 30 40 50
7
5

1 1 1 1 1

</p>