Cod sursa(job #2550695)

Utilizator IoanaStanStan Ioana Ligia IoanaStan Data 19 februarie 2020 00:55:27
Problema Hotel Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <fstream>

using namespace std;
ifstream fin("hotel.in");
ofstream fout("hotel.out");
int n, p, c, i, v[100001];
void c1 (int v[100001])
{
    // rezolvare pentru c=1;
    int i, m;
    fin>>i>>m;
    for (int j=i; j<i+m; j++)
    {
        v[j]=1;
    }

}
void c2 (int v[100001])
{
    // rezolvare pentru c=2;
    int i, m;
    fin>>i>>m;
    for (int j=i; j<i+m; j++)
    {
        v[j]=0;
    }
}
void c3 (int v[100001], int n)
{
    // rezolvare pentru c=3;
    int  l=0, lmax=0;
    for (int j=1; j<=n; j++)
    {
        if (v[j]==0)
        {
            l++;
        }
        else
        {
            if (l>lmax)
                lmax=l;
            l=0;
        }
    }
    if (l>lmax)
    lmax=l;
    fout<<lmax<<endl;
}
int main()
{
    fin>>n>>p;
    for (i=1; i<=p; i++)
    {
        fin>>c;
        if (c==1)
            c1(v);
        else
        {
            if(c==2)
                c2(v);
            else
                c3(v, n);
        }
    }
    return 0;
}