18582022-12-05 16:18:58kdbLeghosszabb béke (75 pont)cpp11Accepted 75/7521ms5224 KiB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

ostream& operator<<(ostream& os, vector<int>& input)
{
    for (auto i : input)
    {
        os << i << " ";
    }
    os << endl;
    return os;
}

int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int>vec(n + 1);
    for (size_t i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        vec[a]++;
        vec[b]--;
    }
    int k = 0, v = 0, c = 0, d = 0;
    for (size_t i = 1; i < n + 1; i++)
    {
        vec[i] += vec[i - 1];
        if (vec[i] > 0) k = i + 1;
        else
        {
            v = i;
            if (v - k > c)
            {
                c = v - k;
                d = k;
            }
        }
    }
    if (c == 0) cout << -1 << endl;
    else cout << c << " " << d + 1 << endl;
    return 0;
}
/*
50 6
3 20
45 46
28 30
12 20
40 48
8 12

*/
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/03ms1832 KiB
2Accepted0/021ms2744 KiB
3Accepted3/32ms2256 KiB
4Accepted3/32ms2456 KiB
5Accepted3/32ms2696 KiB
6Accepted3/32ms2896 KiB
7Accepted3/32ms3068 KiB
8Accepted4/42ms3144 KiB
9Accepted4/42ms3264 KiB
10Accepted4/42ms3616 KiB
11Accepted4/43ms3816 KiB
12Accepted4/44ms3916 KiB
13Accepted4/43ms3796 KiB
14Accepted4/43ms3796 KiB
15Accepted4/44ms4056 KiB
16Accepted4/44ms4308 KiB
17Accepted4/44ms4308 KiB
18Accepted4/44ms4308 KiB
19Accepted4/419ms4828 KiB
20Accepted4/420ms5156 KiB
21Accepted4/419ms5224 KiB
22Accepted4/420ms5172 KiB