72152024-01-03 18:00:30MagyarKendeSZLGLeghosszabb béke (75 pont)cpp17Accepted 75/7568ms6872 KiB
#include <bits/stdc++.h>

#define speed cin.tie(0); ios::sync_with_stdio(0)
#define cinv(v) for (auto& e : v) cin >> e;
#define all(v) v.begin(), v.end()
#define has(s, e) s.count(e)

using namespace std;
using ll = long long;
using point = array<int, 2>;

int main() {
    speed;

    int N, M;
    cin >> N >> M;

    map<int, int> from;

    while (M--) {
        int a, b;
        cin >> a >> b;
        from[a] = max(from[a], b);
    }
    from[N] = N;

    point result = {0, 0};
    int pos = 1;

    for (auto [e, v] : from) {
        if (pos >= N) break;
        if (result[0] < e - pos) {
            result[0] = e - pos;
            result[1] = pos;
        }
        if (e == N) break;
        pos = max(pos, v + 1);
    }


    if (result[0] == 0 && result[1] == 0) {
        cout << -1;
    } else {
        if (result[1] + result[0] == N) {
            result[0]++;
        }
        cout << result[0] << ' ' << result[1];
    }
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/03ms1832 KiB
2Accepted0/068ms5668 KiB
3Accepted3/33ms2288 KiB
4Accepted3/33ms2516 KiB
5Accepted3/33ms2728 KiB
6Accepted3/33ms2940 KiB
7Accepted3/32ms3020 KiB
8Accepted4/42ms3032 KiB
9Accepted4/43ms3152 KiB
10Accepted4/43ms3304 KiB
11Accepted4/46ms3632 KiB
12Accepted4/47ms3840 KiB
13Accepted4/44ms3748 KiB
14Accepted4/46ms3772 KiB
15Accepted4/47ms3976 KiB
16Accepted4/46ms3624 KiB
17Accepted4/46ms3556 KiB
18Accepted4/44ms3528 KiB
19Accepted4/459ms6872 KiB
20Accepted4/443ms3612 KiB
21Accepted4/428ms3684 KiB
22Accepted4/443ms3620 KiB