#P10277. [USACO24OPEN] Bessie's Interview S

[USACO24OPEN] Bessie's Interview S

Description

Bessie is looking for a new job! Fortunately, KK farmers are currently hiring and conducting interviews. Since jobs are highly competitive, the farmers have decided to number and interview cows in the order they applied. There are NN cows that applied before Bessie, so her number is N+1N+1 (1KN31051 \leq K \leq N \leq 3 \cdot 10^5).

The interview process will go as follows. At time 00, farmer ii will start interviewing cow ii for each 1iK1 \leq i \leq K. Once a farmer finishes an interview, he will immediately begin interviewing the next cow in line. If multiple farmers finish at the same time, the next cow may choose to be interviewed by any of the available farmers, according to her preference.

For each 1iN1\le i\le N, Bessie already knows that cow ii's interview will take exactly tit_i minutes (1ti1091 \leq t_i \leq 10^9). However, she doesn't know each cow's preference of farmers.

Since this job is very important to Bessie, she wants to carefully prepare for her interview. To do this, she needs to know when she will be interviewed and which farmers could potentially interview her. Help her find this information!

Input Format

The first line of the input will contain two integers NN and KK.

The second line will contain NN integers t1tNt_1 \dots t_N.

Output Format

On the first line, print the time Bessie's interview will begin.

On the second line, a bit string of length KK, where the ii-th bit is 11 if farmer ii could interview Bessie and 00 otherwise.

6 3
3 1 4159 2 6 5
8
110

Hint

There are 66 cows aside from Bessie and 33 farmers, and the interview process will go as follows:

  1. At time t=0t = 0, farmer 11 interviews cow 11, farmer 22 interviews cow 22, and farmer 33 interviews cow 33.
  2. At time t=1t = 1, farmer 22 finishes his interview with cow 22 and starts interviewing cow 44.
  3. At time t=3t = 3, both farmer 11 and farmer 22 finish their interviews, and there are two possibilities:
  • Farmer 11 interviews cow 55 and farmer 22 interviews cow 66. In this case, farmer 22 would finish his interview at time t=8t = 8 and start interviewing Bessie.
  • Farmer 11 interviews cow 66 and farmer 22 interviews cow 55. In this case, farmer 11 would finish his interview at time t=8t = 8 and start interviewing Bessie.

Thus, Bessie's interview will begin at time t=8t = 8, and she could be interviewed by either farmer 11 or farmer 22.

SCORING:

  • Inputs 2-3: No two farmers finish at the same time.
  • Inputs 4-9: N3103N\le 3\cdot 10^3.
  • Inputs 10-21: No additional constraints.