#abc299b. B - Trick Taking

B - Trick Taking

Score : 200200 points

问题描述

NN 名玩家,编号为 ID 号 1,2,,N1, 2, \ldots, N,正在进行一场纸牌游戏。
每位玩家出一张牌。

每张牌有两个参数:颜色点数,两者都用正整数表示。
对于 i=1,2,,Ni = 1, 2, \ldots, N,玩家 ii 出的牌的颜色为 CiC_i,点数为 RiR_i。所有 R1,R2,,RNR_1, R_2, \ldots, R_N 都互不相同。

NN 名玩家中,将根据以下规则决定一名 胜者

  • 如果有一张或多张颜色为 TT 的牌被打出,那么在这几张牌中点数最大的玩家即为胜者。
  • 如果没有颜色为 TT 的牌被打出,则在所有与玩家 11 打出的牌颜色相同的牌中,点数最大的玩家为胜者。(注意,玩家 11 有可能获胜)

输出胜者的 ID 号。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

NN players with ID numbers 1,2,,N1, 2, \ldots, N are playing a card game.
Each player plays one card.

Each card has two parameters: color and rank, both of which are represented by positive integers.
For i=1,2,,Ni = 1, 2, \ldots, N, the card played by player ii has a color CiC_i and a rank RiR_i. All of R1,R2,,RNR_1, R_2, \ldots, R_N are different.

Among the NN players, one winner is decided as follows.

  • If one or more cards with the color TT are played, the player who has played the card with the greatest rank among those cards is the winner.
  • If no card with the color TT is played, the player who has played the card with the greatest rank among the cards with the color of the card played by player 11 is the winner. (Note that player 11 may win.)

Print the ID number of the winner.

Constraints

  • 2N2×1052 \leq N \leq 2 \times 10^5
  • 1T1091 \leq T \leq 10^9
  • 1Ci1091 \leq C_i \leq 10^9
  • 1Ri1091 \leq R_i \leq 10^9
  • ij    RiRji \neq j \implies R_i \neq R_j
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN TT

C1C_1 C2C_2 \ldots CNC_N

R1R_1 R2R_2 \ldots RNR_N

Output

Print the answer.

Sample Input 1

4 2
1 2 1 2
6 3 4 5

Sample Output 1

4

Cards with the color 22 are played. Thus, the winner is player 44, who has played the card with the greatest rank, 55, among those cards.

Sample Input 2

4 2
1 3 1 4
6 3 4 5

Sample Output 2

1

No card with the color 22 is played. Thus, the winner is player 11, who has played the card with the greatest rank, 66, among the cards with the color of the card played by player 11 (color 11).

Sample Input 3

2 1000000000
1000000000 1
1 1000000000

Sample Output 3

1

update @ 2024/3/10 12:24:01