301187: CF222A. Shooshuns and Sequence

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Shooshuns and Sequence

题意翻译

### 题目描述 有一天,shooshuns发现了$n$个整数的序列,写在黑板上。 shooshuns可以执行一个操作,该操作包括两个步骤: 1. 找到当前序列中第$k$个数字,并将相同的数字添加到序列的末尾; 2. 删除当前序列的第一个数字。 shooshuns想知道板子上的所有数字将要进行多少次操作,才可以让所有数字相同。 ### 输入格式 第一行包含两个以空格分隔的整数$n$和$k$。\ 第二行包含$n$个以空格分隔的整数$a_1,a_2,...,a_n$,表示shooshuns发现的顺序。 ### 输出格式 输出需要多少操作才可以让所有数变成一样的。如果无法实现,请输出$-1$。 ### 样例说明 样例$1$:\ 第一个操作之后,将具有顺序$[1,1,1]$。 因此,一个操作足以使所有数字相同,所以答案等于$1$。 样例$2$:\ 序列将永远不会让所有数字相同。它始终将包含两个不同的数字$3$和$1$。因此,答案等于$-1$。

题目描述

One day shooshuns found a sequence of $ n $ integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps: 1. Find the number that goes $ k $ -th in the current sequence and add the same number to the end of the sequence; 2. Delete the first number of the current sequence. The shooshuns wonder after how many operations all numbers on the board will be the same and whether all numbers will ever be the same.

输入输出格式

输入格式


The first line contains two space-separated integers $ n $ and $ k $ ( $ 1<=k<=n<=10^{5} $ ). The second line contains $ n $ space-separated integers: $ a_{1},a_{2},...,a_{n} $ ( $ 1<=a_{i}<=10^{5} $ ) — the sequence that the shooshuns found.

输出格式


Print the minimum number of operations, required for all numbers on the blackboard to become the same. If it is impossible to achieve, print -1.

输入输出样例

输入样例 #1

3 2
3 1 1

输出样例 #1

1

输入样例 #2

3 1
3 1 1

输出样例 #2

-1

说明

In the first test case after the first operation the blackboard will have sequence \[1, 1, 1\]. So, one operation is enough to make all numbers the same. Thus, the answer equals one. In the second test case the sequence will never consist of the same numbers. It will always contain at least two distinct numbers 3 and 1. Thus, the answer equals -1.

Input

题意翻译

### 题目描述 有一天,shooshuns发现了$n$个整数的序列,写在黑板上。 shooshuns可以执行一个操作,该操作包括两个步骤: 1. 找到当前序列中第$k$个数字,并将相同的数字添加到序列的末尾; 2. 删除当前序列的第一个数字。 shooshuns想知道板子上的所有数字将要进行多少次操作,才可以让所有数字相同。 ### 输入格式 第一行包含两个以空格分隔的整数$n$和$k$。\ 第二行包含$n$个以空格分隔的整数$a_1,a_2,...,a_n$,表示shooshuns发现的顺序。 ### 输出格式 输出需要多少操作才可以让所有数变成一样的。如果无法实现,请输出$-1$。 ### 样例说明 样例$1$:\ 第一个操作之后,将具有顺序$[1,1,1]$。 因此,一个操作足以使所有数字相同,所以答案等于$1$。 样例$2$:\ 序列将永远不会让所有数字相同。它始终将包含两个不同的数字$3$和$1$。因此,答案等于$-1$。

加入题单

算法标签: