DMOPC '20 Contest 2 P4 - Hungry Pigeons

View as PDF

Submit solution


Points: 15 (partial)
Time limit: 0.5s
Memory limit: 256M

Author:
Problem type

There is a flock of N hungry pigeons in Michael's backyard! Fortunately, it has started raining. Every minute, for the next M minutes, one earthworm will surface from his backyard.

The i-th pigeon (1iN) has a beak size of bi. Additionally, the j-th worm (1jM) will have a diameter of dj. A pigeon can eat a worm if and only if the pigeon's beak size is strictly larger than the worm's diameter.

A pigeon's satisfaction is defined as the number of worms that the pigeon has eaten, and the flock's satisfaction is defined to be the minimum satisfaction among all pigeons in the flock. The hungry pigeons want to know: for all 1jM, what is the maximum possible satisfaction of the flock right after the j-th minute?

Constraints

For all subtasks:

1N5×104

1M5×105

1bi109 for all 1iN

1dj109 for all 1jM

Subtask 1 [10%]

N=2

1M20

Subtask 2 [10%]

1N30

1M300

Subtask 3 [20%]

1N2×103

1M2×105

Subtask 4 [30%]

1N2×104

1M2×105

Subtask 5 [30%]

No additional constraints.

Input Specification

The first line of input will contain two space-separated integers N and M.

The second line will contain N space-separated integers b1,b2,,bN.

The third line will contain M space-separated integers d1,d2,,dM.

Output Specification

For all 1jM, output the maximum satisfaction of the flock right after the j-th minute, separated by spaces.

Sample Input

Copy
3 7
6 3 10
4 8 3 2 1 10 7

Sample Output

Copy
0 0 0 1 1 1 2

Explanation of Sample Output

The first three worms are too large for the second pigeon to eat, so the second pigeon must have a satisfaction of 0. Thus, the first three answers are 0.

Then, after the fourth minute, it is possible for all pigeons to have a satisfaction of 1 (e.g. the pigeons of beak sizes 6, 3, and 10 can eat worms of diameter 4, 2, and 8, respectively). Thus, the next answer is 1.

After the fifth minute, it is possible for any individual pigeon to eat at least 2 worms. However, there are not enough worms for all the pigeons to have a satisfaction of 2 at the same time, so the maximum possible satisfaction of the flow is still 1. The same situation occurs after the sixth minute, since no pigeon is able to eat the worm of size 10.

After the seventh minute, it is finally possible for the flock to have a satisfaction of 2.


Comments

There are no comments at the moment.