47702023-03-31 11:33:36EyusieLeghosszabb béke (75 pont)cpp17Time limit exceeded 71/75216ms4212 KiB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    iostream::sync_with_stdio(0);
    cin.tie();
    int n, k;
    cin >> n >> k;
    bool* a = new bool[n+1] { 0 };
    int m, l;
    for(int i = 0; i < k; i++)
    {
        cin >> m >> l;
        fill(a+m, a+l+1,1);
    }
    int mx = 0;
    int counter = 0;
    int indmx = 0;
    int indcur = 0;
    for(int i = 1; i <= n; i++)
    {
        if(a[i])
        {
            if(mx < counter)
            {
                indmx = indcur;
                mx = counter;
            }
            counter = 0;
        }
        else
        {
            if(counter == 0)
            {
                indcur = i;
                counter++;
            }
            else counter++;
        }
    }
    if(mx < counter)
    {
        mx = counter;
        indmx = indcur;
    }
    if(mx == 0)
    {
        cout << "-1";
    }
    else cout << mx << " " << indmx;
}
SubtaskSumTestVerdictTimeMemory
base71/75
1Accepted0/03ms1700 KiB
2Accepted0/032ms2088 KiB
3Accepted3/33ms2052 KiB
4Accepted3/33ms2284 KiB
5Accepted3/33ms2512 KiB
6Accepted3/33ms2708 KiB
7Accepted3/33ms2916 KiB
8Accepted4/43ms3128 KiB
9Accepted4/43ms3348 KiB
10Accepted4/43ms3564 KiB
11Accepted4/44ms3896 KiB
12Accepted4/44ms4012 KiB
13Accepted4/44ms3856 KiB
14Accepted4/44ms3860 KiB
15Accepted4/44ms4132 KiB
16Accepted4/44ms4104 KiB
17Accepted4/46ms4120 KiB
18Accepted4/410ms4124 KiB
19Accepted4/439ms4212 KiB
20Accepted4/4165ms4208 KiB
21Time limit exceeded0/4216ms4148 KiB
22Accepted4/4165ms4148 KiB