147952025-02-02 17:54:18sarminLeghosszabb béke (75 pont)cpp17Accepted 75/7523ms832 KiB
// Created by Armin on 2/1/2025.

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pp = pair<int, int>;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    
    int n, m; cin >> n >> m;
    vector<int> prefix(n + 2);
    for (int i = 0; i < m; i++) {
      int a, b; cin >> a >> b;
      prefix[a]++;
      prefix[b + 1]--;
    }
    
    for (int i = 1; i <= n; i++) {
      prefix[i] += prefix[i - 1];
    }
    prefix[0] = 1;
    prefix[n + 1] = 1;
    
    int start = 0, maxstart = 0, maxlength = -1;
    for (int i = 1; i <= n + 1; i++) {
      if (prefix[i] != 0) {
        if (i - start - 1 > maxlength) {
          maxlength = i - start - 1;
          maxstart = start + 1;
        }
        start = i;
      }
    }
    if (maxlength > 0) {
      cout << maxlength << " " << maxstart;
    } else {
      cout << "-1\n";
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/01ms316 KiB
2Accepted0/023ms820 KiB
3Accepted3/31ms316 KiB
4Accepted3/31ms316 KiB
5Accepted3/31ms316 KiB
6Accepted3/31ms508 KiB
7Accepted3/31ms316 KiB
8Accepted4/41ms316 KiB
9Accepted4/41ms316 KiB
10Accepted4/41ms500 KiB
11Accepted4/42ms316 KiB
12Accepted4/43ms316 KiB
13Accepted4/42ms316 KiB
14Accepted4/42ms508 KiB
15Accepted4/43ms492 KiB
16Accepted4/43ms536 KiB
17Accepted4/43ms564 KiB
18Accepted4/43ms564 KiB
19Accepted4/420ms832 KiB
20Accepted4/420ms820 KiB
21Accepted4/420ms820 KiB
22Accepted4/420ms820 KiB