Cod sursa(job #308431)

Utilizator andrici_cezarAndrici Cezar andrici_cezar Data 27 aprilie 2009 09:20:56
Problema Hotel Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.05 kb
#include<fstream.h>

long i,u,lungmax,ok,l,ll,l2,lung,n,p,a,b,c,o;
short cam[100000];

int main()
{
ifstream f("hotel.in");
ofstream g("hotel.out");
f>>n>>p;
for (i=1;i<=p;i++)
    {
    u=a;
    f>>a;
    ok=0;
    if (a==1)
       {
       f>>b>>c;
       if (b>ll || c<l2) ok=1;
       for (o=b;o<=b+c-1;o++)
             cam[o]=1;
       }
    else if (a==2)
         {
         f>>b>>c;
         if (b==ll) ok=1;
         else if (c-b+1>l2-ll+1) ok=1;
         for (o=b;o<=b+c-1;o++)
               cam[o]=0;
         }
    else if (a==3)
         {
         if (u!=3 || ok==1)
            {
            lung=0;
            lungmax=0;
            l=1;
            for (o=1;o<=n;o++)
                if (cam[o]==0) lung++;
                else {
                     if (lung>lungmax) { lungmax=lung;ll=l;l2=o;}
                     lung=0;
                     ll=o;
                     }
            if (lung>lungmax) lungmax=lung;
            }
            g<<lungmax<<'\n';
            }
    }
g.close();
return 0;
}