Cod sursa(job #247873)

Utilizator raica_cristiraica dumitru cristian raica_cristi Data 24 ianuarie 2009 13:20:54
Problema Secventa Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.76 kb
#include<stdio.h>
#define dim 500001
int a[dim];
int main ()
{
    int n,i,k,m,x,y;
    int min,xmax,xmin,lmin,nr;
    xmax=xmin=lmin=0;
    freopen("secventa.in","r",stdin);
    freopen("secventa.out","w",stdout);
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++)
    scanf("%d",&a[i]);
    for(i=1;i<=n;i++)
    {
                     min=a[i];
                     x=i-1;
                     y=i+1;
                     while(1)
                     {nr=0;
                             if(x>=1)
                             {
                                     if(min<=a[x])
                                              x--;
                                              else
                                              nr++;
                             }
                              else
                                              nr++;
                             if(y<=n)
                             {       
                                     if(min<=a[y])
                                             y++;
                                             else
                                             nr++;
                             }
                              else
                                              nr++;
                             if(nr==2)
                             break;
                     if(y-x-1>=m)
                     {
                               if(min>lmin)
                               {
                                           xmin=x;
                                           xmax=y;
                                           lmin=min;
                                           }}
                                           }}
printf("%d %d %d",xmin+1,xmax-1,lmin);
return 0;
}