Pagini recente » Cod sursa (job #1678513) | Cod sursa (job #2095084) | Cod sursa (job #1242474) | Cod sursa (job #697518) | Cod sursa (job #537154)
Cod sursa(job #537154)
#include<stdio.h>
using namespace std;
long int n;
long int k;
long int A[500001];
long int Deck[500001];
long int Front = 1;
long int Back = 0;
long int mar = 0;
long int poz;
void citire(void)
{
FILE *f = fopen("secventa.in","r");
fscanf(f,"%d %d",&n,&k);
for(int i=1;i<=n;i++)
{
fscanf(f,"%d ",&A[i]);
while(Front <= Back && A[i]<=A[Deck[Back]]) Back --;
Deck[++Back] = i;
if(Deck[Front] == i-k) ++Front;
if(mar <= A[Deck[Front]])
{
mar = A[Deck[Front]];
poz = Deck[Front];
}
}
fclose(f);
}
int main()
{
FILE *f = fopen("secventa.out","w");
citire();
fprintf(f,"%d %d %d",poz,poz+k-1,mar);
fclose(f);
return 0;
}