Cod sursa(job #333057)

Utilizator Alexa_ioana_14Antoche Ioana Alexandra Alexa_ioana_14 Data 21 iulie 2009 12:58:38
Problema Secventa Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 500001
struct sec{int val,poz;} v[N];
int n,k;
bool compar(const sec&a,const sec&b)
{
	if (a.val>b.val) return true;
	if (a.val==b.val)
		if (a.poz<=b.poz)
			return true;
	return false;
	
}
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].val);
		v[i].poz=i;
	}
	sort(v+1,v+n+1,compar);
	for (int i=1; i<=n; ++i)
	{
		int x=n-v[i].poz+1;
		if (x>=k)
		{
			printf("%d %d %d",v[i].poz,n,v[i].val);
			return;
		}
	}
}
int main()
{
	citire();
	return 0;
}