Skip to content

Instantly share code, notes, and snippets.

@brickgao
Created September 11, 2012 17:30
Show Gist options
  • Save brickgao/3700056 to your computer and use it in GitHub Desktop.
Save brickgao/3700056 to your computer and use it in GitHub Desktop.
Codeforces Round #137 (Div. 2) A
//by Brickgao
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
using namespace std;
__int64 a[100100];
int main()
{
__int64 n, k, ans, i;
bool flag;
while(~scanf("%I64d%I64d", &n, &k))
{
for(i = 1; i <= n; i++)
scanf("%I64d", &a[i]);
flag = true;
for(i = k + 1; i <= n; i++)
if(a[k] != a[i])
{
flag = false;
break;
}
if(!flag)
{
printf("-1\n");
}
else
{
for(i = k - 1; i >= 1; i --)
if(a[i] != a[k])
break;
ans = i;
printf("%I64d\n", ans);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment