Cod sursa(job #3347735)

Utilizator Gabriel_DaescuDaescu Gabriel Florin Gabriel_Daescu Data 18 martie 2026 09:23:10
Problema Hotel Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1 kb
#include <fstream>
#define NMAX 100005
using namespace std;
ifstream  fin("hotel.in");
ofstream fout("hotel.out");
int N,P,v[NMAX];
int main()
{
    fin>>N>>P;

    int op,poz,M;
    for(int q=1; q<=P; q++)
    {
        fin>>op;

        if(op==1)
        {
            fin>>poz>>M;
            for(int i=poz; i<=poz+M-1; i++)
            {
                v[i]=1;
            }
        }

        if(op==2)
        {
            fin>>poz>>M;
            for(int i=poz; i<=poz+M-1; i++)
            {
                v[i]=0;
            }
        }

        if(op==3)
        {
            int l,lmax;
            lmax=l=0;

            for(int i=1; i<=N; i++)
            {
                if(!v[i])
                {
                    l++;
                    lmax=max(lmax,l);
                }
                else
                {
                    l=0;
                }
            }

            fout<< lmax << "\n";
        }
    }

    return 0;
}