Cod sursa(job #3297906)

Utilizator teodor_tohteodor toh teodor_toh Data 24 mai 2025 11:38:13
Problema Hotel Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.8 kb
#include<iostream>
#include<fstream>
#include<vector>
using namespace std;
ifstream fin("hotel.in");
ofstream fout("hotel.out");

int n, p, c, s, m;
vector<int> arr;
int main()
{
	int sum = 0, maxLen, len;
	fin >> n >> p;
	arr.resize(n + 2);
	for (int i = 0; i < p; i++)
	{
		fin >> c;
		if (c == 1 || c == 2)
			fin >> s >> m;

		if (c == 1)
		{
			arr[s]++;
			arr[s + m]--;
		}
		else if (c == 2)
		{
			arr[s]--;
			arr[s + m]++;
		}
		else if (c == 3)
		{
			maxLen = -1;
			len = 0;
			sum = arr[1];
			for (int i = 1; i <= n; i++)
			{
				if (sum == 0)
					len++;
				else if (sum == 1 || i == n)
				{
					if (len > maxLen)
						maxLen = len;
					len = 0;
				}
				sum += arr[i + 1];
			}
			fout << maxLen << "\n";
			cout << maxLen << "\n";
		}
	}
}