Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- int n, k;
- cin >> n >> k;
- vector<int>v(n);
- for (int i=0; i<n; i++) {
- cin >> v[i];
- }
- int x=v[k-1];
- for (int i=k; i<n; i++) {
- if (v[i]!=x) {
- cout << -1;
- return 0;
- }
- }
- for (int i=n-1; i>-1; i--) {
- if (v[i]!=x) {
- cout << i+1;
- return 0;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment