87532024-01-28 17:46:34IgnácLeghosszabb béke (75 pont)cpp17Accepted 75/7582ms5376 KiB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> war(m);
	for (int i = 0; i < m; i++) {
		cin >> war[i].first >> war[i].second;
	}

	sort(war.begin(), war.end());
	int end = 0, maxh = 0, maxk = 0;
	for (int i = 0; i < m; i++) {
		if (war[i].first > end + 1) {
			if (war[i].first - end - 1 > maxh) {
				maxh = war[i].first - end - 1;
				maxk = end + 1;
			}
		}

		if (war[i].second > end) end = war[i].second;
	}

	if (n - end > maxh) {
		maxh = n - end;
		maxk = end + 1;
	}

	if (maxh == 0) cout << -1;
	else cout << maxh << " " << maxk; 
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/03ms1816 KiB
2Accepted0/082ms3408 KiB
3Accepted3/33ms2264 KiB
4Accepted3/33ms2472 KiB
5Accepted3/33ms2836 KiB
6Accepted3/33ms2820 KiB
7Accepted3/33ms3044 KiB
8Accepted4/43ms3268 KiB
9Accepted4/43ms3524 KiB
10Accepted4/43ms3696 KiB
11Accepted4/47ms3788 KiB
12Accepted4/48ms3804 KiB
13Accepted4/46ms3784 KiB
14Accepted4/47ms3788 KiB
15Accepted4/48ms3804 KiB
16Accepted4/48ms3956 KiB
17Accepted4/48ms3880 KiB
18Accepted4/49ms3820 KiB
19Accepted4/475ms5072 KiB
20Accepted4/476ms5376 KiB
21Accepted4/474ms5288 KiB
22Accepted4/476ms5288 KiB