-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcp104.cpp
More file actions
42 lines (36 loc) · 702 Bytes
/
Copy pathcp104.cpp
File metadata and controls
42 lines (36 loc) · 702 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, k;
cin >> n >> k;
vector<int> v(n);
for(int i=0; i<n; i++){
cin >> v[i];
}
int c =0;
for(int i=0; i<n; i++){
auto it = v.begin()+k;
int ele = v[k-1];
v.erase(it);
v.push_back(ele);
int sec = v[0];
if(sec == ele){
c = i+1;
break;
}
v.erase(v.begin());
}
int f =0;
for(int i=0; i<n-1 ;i++){
if(v[i] != v[i+1]){
f =1;
}
}
if(f == 1){
cout << -1 << endl;
}
else{
cout << c << endl;
}
return 0;
}