Pagini recente » Cod sursa (job #1698676) | Cod sursa (job #92124) | Cod sursa (job #1863712) | Cod sursa (job #2859647) | Cod sursa (job #603697)
Cod sursa(job #603697)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct list
{
int info, poz;
list *urm, *prec;
} *p, *u;
int n ,k;
char s[5000000];
int main()
{
int x, max = -31000;
int i, umax = 0;
list *nod, *aux;
char *xs;
freopen("secventa.in", "r", stdin);
freopen("secventa.out", "w", stdout);
scanf("%d %d", &n, &k);
gets(s);
gets(s);
xs = strtok(s, " ");
i = 1;
while(xs != NULL)
{
x = atoi(xs);
while(u && u->info > x)
{
if(u == p)
{
p = NULL;
}
aux = u->prec;
delete u;
u = aux;
}
nod = new list;
nod->info = x;
nod->poz = i;
nod->prec = u;
//nod->urm = NULL;
if(!p)
{
p = nod;
}
if(u)
{
u->urm = nod;
}
u = nod;
if(nod->poz - p->poz >= k)
{
aux = p->urm;
delete p;
p = aux;
p->prec = NULL;
}
if(i>=k && max < p->info)
{
max = p->info;
umax = u->poz - k + 1;
}
xs = strtok(NULL, " ");
i++;
}
printf("%d %d %d", umax, umax + k -1, max);
return 0;
}