242222026-02-06 21:19:07sarminLeghosszabb béke (75 pont)python3Runtime error 0/7516ms3316 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// const ll MOD = 1e9+7;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m; cin >> n >> m;
    vector<int> p(n+2, 0);
    int u, v;
    for (int i = 0; i < m; i++) {
    	cin >> u >> v;
    	p[u]++; p[v+1]--;
    }
    
    for (int i = 1; i <= n; i++) {
    	p[i] += p[i-1];
    }
    
    
    int l = 0, r = 0;
    int mx = -1, first = 0;
	while (r <= n) {
		//cerr << l << " " << r << "\n";
		r = max(l, r);
		if (p[l] != 0) {
			l++;
			//cerr << "l++\n";
		} else {
			//cerr <<"itt\n";
			while (p[r+1] == 0 && r <= n) {
				r++;
				//cerr << "r++\n";
			}
			if (r-l+1 > mx) {
				mx = r-l+1; first = l;
			}
			l++;
		}
	}
	
	if (mx == -1) cout << -1 << "\n";
	else {
		cout << mx << " " << first << "\n";
	}

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/75
1Runtime error0/016ms3060 KiB
2Runtime error0/016ms3152 KiB
3Runtime error0/316ms2868 KiB
4Runtime error0/316ms2868 KiB
5Runtime error0/316ms2956 KiB
6Runtime error0/316ms2804 KiB
7Runtime error0/316ms3052 KiB
8Runtime error0/414ms2820 KiB
9Runtime error0/414ms3224 KiB
10Runtime error0/414ms3132 KiB
11Runtime error0/414ms3316 KiB
12Runtime error0/416ms2868 KiB
13Runtime error0/416ms3048 KiB
14Runtime error0/414ms2916 KiB
15Runtime error0/414ms2944 KiB
16Runtime error0/414ms2996 KiB
17Runtime error0/416ms2868 KiB
18Runtime error0/414ms2884 KiB
19Runtime error0/414ms3036 KiB
20Runtime error0/414ms3040 KiB
21Runtime error0/414ms3128 KiB
22Runtime error0/416ms3040 KiB