#P9292. [ROI 2018] Robomarathon

[ROI 2018] Robomarathon

Background

Translated from ROI 2018 Day2 T3. Робомарафон (Robomarathon).

Problem Description

There are NN robot runners in a marathon, numbered 1N1 \ldots N. The track has NN lanes, also numbered 1N1 \ldots N. Each runner occupies one lane: runner ii (or simply ii) is in lane ii (or simply lane ii). All lanes have the same distance from start to finish. It is known that runner ii needs aia_i seconds to finish the whole distance.

At the start of each lane there is a starting horn, but it does not play sound. The referee played a prank and turned off the starting horns on some lanes.

When the time comes, all starting horns that are on will send the start signal at the same time (called “firing” below). If lane ii fires, runner ii will start immediately.

The start signal propagates at a speed of 11 lane per second. For example, if only lane 44 fires, then after one second runners 33 and 55 will receive the signal and start immediately; after two seconds runners 22 and 66 will receive the signal and start immediately. Suppose runner ii starts at second xix_i, then they will finish at second fi=ai+xif_i = a_i + x_i.

We rank runners by their finishing order. For example, if n=3n=3, f1=f2=4f_1 = f_2 = 4, and f3=5f_3 = 5, then runner 11 and runner 22 are tied for first place, and runner 33 is third.

As you can see, the ranking depends on which starting horns are turned on. Please find, for each runner, their best possible rank or their worst possible rank.

Input Format

The first line contains nn, pp.

The next line contains nn numbers, representing a1,a2ana_1, a_2 \ldots a_n.

Output Format

If p=1p = 1, output the best possible rank.

If p=2p = 2, output the worst possible rank.

5 1
8 5 5 7 7
3
1
1
2
1
5 2
8 5 5 7 7
5
3
2
4
5

Hint

For all testdata, 1n4×1051 \leq n \leq 4 \times 10^5, 0ai1090 \leq a_i \leq 10^9.

Subtask ID nn pp
11 1n201 \leq n \leq 20 p=1p = 1
22 p=2p = 2
33 1n4×1051 \leq n \leq 4 \times 10^5 p=1p = 1
44 p=2p = 2

In Subtasks 33 and 44, each test point is worth 11 point, and the total score is the sum.

Translated by ChatGPT 5