#P6138. [IOI 2012] 骑马比武竞赛
[IOI 2012] 骑马比武竞赛
Description
In 1491, Duke Milan Lodovico Sforza asked Leonardo to prepare the celebration for his wedding with Beatrice d'Este. The celebration included a grand three-day jousting tournament, but the most popular knight was late...
In a jousting tournament, knights are initially lined up in a row and numbered from to according to their positions. In each round, the host calls two positions and (where ). All knights whose positions are between and (inclusive) start jousting. The final winner stays in the tournament and returns to his original position, while all losers leave the tournament. After that, the remaining knights close ranks in their original order, filling the empty positions. Their positions are then renumbered from to . The host then proceeds to the next round, until only one knight remains.
Leonardo knows that all knights have different strengths, ranging from (weakest) to (strongest). He also knows exactly what commands the host will give for rounds, because Leonardo can do anything. He is also sure that in each round, the knight with the greatest strength will win.
Among the knights, knights have already lined up, but the most popular knight has not appeared yet. This late knight has strength . To make the tournament reach its climax, Leonardo wants this knight to show his style well, so he wants to insert him into a position such that he can win the maximum number of rounds. Note that we do not care about rounds that do not involve this knight. We only care about rounds that include this knight and are won by him.
Example
Suppose there are knights, and of them have already lined up with strengths . The late knight has strength . Suppose there will be rounds, and the host plans to call positions as , , .
If Leonardo inserts the late knight into the first position, then the strengths become . In the first round, the knights at positions participate, with strengths , so the knight with strength wins. After this round, the new sequence of strengths becomes . In the next round, the knights with strengths and (positions ) compete, and the knight with strength wins. The sequence then becomes . In the last round (positions ), the knight with strength wins. Therefore, the late knight wins only one round (the second round).
If Leonardo inserts the late knight between the knights with strengths and , then the strengths become . This time, in the first round the participating strengths are . The knight with strength wins, and the sequence becomes . In the second round, the knight with strength faces the knight with strength , and the knight with strength wins. In the last round, the sequence becomes , and the knight with strength wins. In this arrangement, the late knight wins two rounds. This is actually the best position, because no other position allows the late knight to win more than two rounds.
Your task is to write a program to help the late knight choose the best position so that he can win the maximum number of rounds, meeting Leonardo’s expectations.
Input Format
- The first line contains integers , , , where is the number of knights, is the number of rounds the host will conduct, and is the strength of the late knight.
- The second line contains integers , representing the strengths of the knights already lined up.
- The third line contains integers . For , in round the host makes the knights from position to position (inclusive) compete. You may assume that for each , .
Output Format
Output one line: the position that allows the late knight to win the maximum number of rounds. If there are multiple optimal positions, output the smallest index.
5 3 3
1 0 2 4
1 3
0 1
0 1
1
Hint
For of the data, , . In round , is less than the number of knights remaining in that round. After the commands, there will be only one knight left.
Translated by ChatGPT 5
京公网安备 11011102002149号