304291: CF818D. Multicolored Cars
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Multicolored Cars
题意翻译
【题目描述】 定义$cnt_{x}(i)$表示到$i$时刻$x$出现过的个数。 现在给出$n$个数$a_{1},a_{2}……a_{n}$,$a_{i}$表示时刻$i$出现的数。$Alice$选择了一个数$m$,请帮助$Bob$选择一个数$k$,使得对任意时刻$i$,都有$cnt_{k}(i)>=cnt_{m}(i)$。若不存在这样的$k$请输出$-1$。 【输入格式】 第一行两个整数$n$,$m$,表示有$n$个数,$Alice$选择了的数$m$。 第二行$n$个整数$a_{1},a_{2}……a_{n}$,$a_{i}$表示时刻$i$出现的数。 【输出格式】 存在这样的$k$请输出任意一个可行解,若不存在这样的$k$请输出$-1$。 【数据范围】 所有数不超过$10^6$题目描述
Alice and Bob got very bored during a long car trip so they decided to play a game. From the window they can see cars of different colors running past them. Cars are going one after another. The game rules are like this. Firstly Alice chooses some color $ A $ , then Bob chooses some color $ B $ ( $ A≠B $ ). After each car they update the number of cars of their chosen color that have run past them. Let's define this numbers after $ i $ -th car $ cnt_{A}(i) $ and $ cnt_{B}(i) $ . - If $ cnt_{A}(i)>cnt_{B}(i) $ for every $ i $ then the winner is Alice. - If $ cnt_{B}(i)>=cnt_{A}(i) $ for every $ i $ then the winner is Bob. - Otherwise it's a draw. Bob knows all the colors of cars that they will encounter and order of their appearance. Alice have already chosen her color $ A $ and Bob now wants to choose such color $ B $ that he will win the game (draw is not a win). Help him find this color. If there are multiple solutions, print any of them. If there is no such color then print -1.输入输出格式
输入格式
The first line contains two integer numbers $ n $ and $ A $ ( $ 1<=n<=10^{5},1<=A<=10^{6} $ ) – number of cars and the color chosen by Alice. The second line contains $ n $ integer numbers $ c_{1},c_{2},...,c_{n} $ ( $ 1<=c_{i}<=10^{6} $ ) — colors of the cars that Alice and Bob will encounter in the order of their appearance.
输出格式
Output such color $ B $ ( $ 1<=B<=10^{6} $ ) that if Bob chooses it then he will win the game. If there are multiple solutions, print any of them. If there is no such color then print -1. It is guaranteed that if there exists any solution then there exists solution with ( $ 1<=B<=10^{6} $ ).
输入输出样例
输入样例 #1
4 1
2 1 4 2
输出样例 #1
2
输入样例 #2
5 2
2 2 4 5 3
输出样例 #2
-1
输入样例 #3
3 10
1 2 3
输出样例 #3
4