#P3434. [POI 2006] KRA-The Disks

[POI 2006] KRA-The Disks

Description

On his birthday, Johnny received a gift from his parents: a tube and a set of disks. The tube is composed of several cylindrical segments of equal height, and each disk has the same height as one segment. Each cylindrical segment has a hole, and the hole diameters may differ between segments.

Johnny invented a game: he inserts the disks into the tube in a given order and wants to determine at which depth (level) the last disk will stop.

A disk stops falling in two cases: either it cannot pass through a small hole (i.e., the hole’s diameter is smaller than the disk’s diameter), or it is blocked by previously inserted disks.

Johnny is puzzled by his own game. He asks you to solve this problem for him.

Input Format

The first line contains two integers nn and mm, the tube’s depth (number of segments) and the number of disks, respectively.

The second line contains nn integers rir_i, where rir_i is the diameter of the hole in the ii-th segment of the tube.

The third line contains mm integers kik_i, where kik_i is the diameter of the ii-th disk inserted into the tube.

Output Format

Output a single integer: the level at which the last disk will rest.

If the last disk cannot be inserted into the tube, output 00.

7 3
5 6 4 3 6 2 3
3 2 5
2

Hint

Constraints: 1n,m3×1051 \le n,m \le 3 \times 10^5, 1ri,ki1091 \le r_i,k_i \le 10^9.

Translated by ChatGPT 5