Pagini recente » Cod sursa (job #934371) | Cod sursa (job #1508525) | Cod sursa (job #2570315) | Cod sursa (job #584354) | Cod sursa (job #820277)
Cod sursa(job #820277)
#include <cstdio>
#include <cstdlib>
FILE*f;
FILE*g;
#define maxn 5000001
int A[ maxn ],deq[ maxn ], poz[ maxn ];
long long s;
int n,k,i,st,dr,ind1,ind2,max;
int main()
{
f=fopen("secventa.in","r");
g=fopen("secventa.out","w");
fscanf(f,"%d%d",&n,&k);s=0;
for (i=1;i<=n;i++)
fscanf(f,"%d",&A[i]);
st=1;dr=0;max=A[1];ind1=1;ind2=1;
for (i=1;i<=n;i++)
{ while ((A[i]<=deq[dr]) && (st<=dr))
dr--;
deq[++dr]=A[i];
poz[dr] = i;
if (poz[st]==i-k) st++;
if ((i>=k) && (deq[st]>max)) {ind1=poz[st];ind2=poz[dr];max=deq[st];}
}
fprintf(g,"%d %d %d",ind1,ind2,max);
return 0;
}