18162022-12-04 00:18:47kdbLeghosszabb béke (75 pont)cpp11Wrong answer 72/7523ms5064 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 + 2);
    for (size_t i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        vec[a]++;
        vec[b]--;
    }
    vec[n + 1] = 1;
    int a = 0, b = 0, c = 0, d = 0;
    for (size_t i = 1; i < n + 2; i++)
    {
        vec[i] += vec[i - 1];
        if (vec[i] == 0) a++;
        else
        {
            if (a > c)
            {
                c = a;
                d = b;
            }
            b = i;
            a = 0;
        }
    }
    if (c == 1) cout << -1 << endl;
    else cout << c - 1 << " " << d + 2 << endl;
    return 0;
}
/*
50 6
3 20
45 46
28 30
12 20
40 48
8 12

*/
SubtaskSumTestVerdictTimeMemory
base72/75
1Accepted0/03ms1824 KiB
2Accepted0/023ms2712 KiB
3Accepted3/32ms2220 KiB
4Wrong answer0/32ms2456 KiB
5Accepted3/32ms2680 KiB
6Accepted3/32ms2756 KiB
7Accepted3/32ms2736 KiB
8Accepted4/42ms2872 KiB
9Accepted4/42ms2944 KiB
10Accepted4/42ms3220 KiB
11Accepted4/43ms3164 KiB
12Accepted4/44ms3208 KiB
13Accepted4/43ms3484 KiB
14Accepted4/43ms3424 KiB
15Accepted4/44ms3424 KiB
16Accepted4/44ms3708 KiB
17Accepted4/44ms3964 KiB
18Accepted4/44ms4016 KiB
19Accepted4/419ms4664 KiB
20Accepted4/420ms4808 KiB
21Accepted4/419ms4744 KiB
22Accepted4/420ms5064 KiB