Cod sursa(job #341143)

Utilizator Alexa_ioana_14Antoche Ioana Alexandra Alexa_ioana_14 Data 17 august 2009 16:57:07
Problema Secventa Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 kb
#include<cstdio>
#define N 500001
#include<algorithm>
using namespace std;
int n,k,v[N];
struct secventa{int v,p;}x[N];
bool compar(const secventa&a,const secventa&b)
{
	return a.v>b.v;
}
void citire()
{
	freopen("secventa.in","r",stdin);
	freopen("secventa.out","w",stdout);
	scanf("%d%d",&n,&k);
	for (int i=1; i<=n; ++i)
	{
		scanf("%d",&v[i]);
		x[i].v=v[i];
		x[i].p=i;
	}
	sort(x+1,x+1+n,compar);
}
void secventa()
{
	for (int i=k; i<=n; ++i)
	{
		int g=x[i].p,num=1;
		while (g-1&&x[i].v<v[g-1])
		{
			++num;
			--g;
		}
		if (num>=k)
		{
			printf("%d %d %d",g,x[i].p,x[i].v);
			return;
		}
		g=x[i].p;
		num=1;
		while (g+1<=n&&x[i].v<v[g+1])
		{
			++num;
			++g;
		}
		if (num>=k)
		{
			printf("%d %d %d",g,x[i].p,x[i].v);
			return;
		}
	}
}
int main()
{
	citire();
	secventa();
	return 0;
}