#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 and , the tube’s depth (number of segments) and the number of disks, respectively.
The second line contains integers , where is the diameter of the hole in the -th segment of the tube.
The third line contains integers , where is the diameter of the -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 .
7 3
5 6 4 3 6 2 3
3 2 5
2
Hint
Constraints: , .
Translated by ChatGPT 5
京公网安备 11011102002149号