Pagini recente » Cod sursa (job #805887) | Cod sursa (job #1135040) | Cod sursa (job #1400550) | Cod sursa (job #1716440) | Cod sursa (job #560043)
Cod sursa(job #560043)
#include<stdio.h>
#define NMax 500001
#define Inf 30001
FILE *f=fopen("secventa.in","r");
FILE *g=fopen("secventa.out","w");
int n,k,x[NMax],aux,st,dr,a[NMax],max=-Inf,pozmax,b;
void Read()
{int i;
fscanf(f,"%d %d",&n,&k);
for(i=1;i<=n;i++)
fscanf(f,"%d",&x[i]);
}
void Solve()
{int i,min,j;
min=x[1];
for(i=2;i<=k;i++)
if(min > x[i]) {min = x[i]; aux = 2;}
a[k] = min;//retinem minimul pt fiecare pereche
if(a[k] > max) {max = a[k]; pozmax = k; }
for(i=k+1;i<=n;i++)
{ if(x[i] < a[i-1])
a[i] = x[i];
else
{
min = x[i];
for(j=i; j>=i-k+1; j--)
if(min > x[j]) min = x[j];
a[i] = min;
}
if(a[i] > max) {max = a[i]; pozmax = i;}
else if(a[i] == max) if(pozmax > i) pozmax = i;
aux = i-k+1;
}
}
void Reverse()
{int i,aux;
for(i=1;i<=n/2;i++)
{
aux = x[i];
x[i] = x[n-i+1];
x[n-i+1] = aux;
}
}
int main()
{
Read();
Solve();
dr = pozmax;
b = max;
max = -Inf;
Reverse();
Solve();
st=n - pozmax+1;
fprintf(g,"%d %d %d",st,dr,b);
return 0;
}