杭电ACM比赛的一道题目,A.Shooshuns and SequenceTime Limit :4000/2000ms (Java/Other) Memory Limit :524288/262144K (Java/Other)Total Submission(s) :130 Accepted Submission(s) :34Problem DescriptionOne day shooshuns found a sequence of n integer
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/07 16:53:29
杭电ACM比赛的一道题目,A.Shooshuns and SequenceTime Limit :4000/2000ms (Java/Other) Memory Limit :524288/262144K (Java/Other)Total Submission(s) :130 Accepted Submission(s) :34Problem DescriptionOne day shooshuns found a sequence of n integer
杭电ACM比赛的一道题目,
A.Shooshuns and Sequence
Time Limit :4000/2000ms (Java/Other) Memory Limit :524288/262144K (Java/Other)
Total Submission(s) :130 Accepted Submission(s) :34
Problem Description
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.
Input
The first line contains two space-separated integers n and k (1≤k≤n≤105).
The second line contains n space-separated integers:a1,a2,...,an (1≤ai≤105) the sequence that the shooshuns found.
Output
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.
Sample Input
3 2
3 1 1
3 1
3 1 1
Sample Output
1
-1
Source
Codeforces
我想知道怎么去确定一个最大的操作次数,若大于这个次数就判断为一直不相等,然后输出-1?
杭电ACM比赛的一道题目,A.Shooshuns and SequenceTime Limit :4000/2000ms (Java/Other) Memory Limit :524288/262144K (Java/Other)Total Submission(s) :130 Accepted Submission(s) :34Problem DescriptionOne day shooshuns found a sequence of n integer
经过刚才的讨论,大家都学习到了.希望你在ACM的道路上取得长足进步.