242232026-02-06 21:19:30sarminLeghosszabb béke (75 pont)cpp17Wrong answer 27/7524ms1588 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
base27/75
1Accepted0/01ms316 KiB
2Wrong answer0/024ms1588 KiB
3Wrong answer0/31ms316 KiB
4Wrong answer0/31ms316 KiB
5Wrong answer0/31ms316 KiB
6Accepted3/31ms316 KiB
7Wrong answer0/31ms316 KiB
8Wrong answer0/41ms332 KiB
9Wrong answer0/41ms316 KiB
10Wrong answer0/41ms332 KiB
11Wrong answer0/43ms464 KiB
12Wrong answer0/43ms316 KiB
13Wrong answer0/42ms388 KiB
14Wrong answer0/42ms492 KiB
15Wrong answer0/43ms564 KiB
16Accepted4/43ms316 KiB
17Accepted4/43ms564 KiB
18Accepted4/43ms568 KiB
19Wrong answer0/421ms1296 KiB
20Accepted4/421ms1040 KiB
21Accepted4/419ms820 KiB
22Accepted4/421ms1012 KiB