72132024-01-03 16:43:47MagyarKendeSZLGTalálkozáscpp17Accepted 55/5537ms5052 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>;

const int INF = 100'000;

int main() {
	speed;

	int N;
	cin >> N;

	vector<int> beginS(N), endS(N);

	for (int i = 0; i < N; i++) {
		cin >> beginS[i] >> endS[i];
	}

	sort(all(beginS));
	sort(all(endS));	

	int
	H = N / 2 + (N & 1),
	curr = 0,
	begin = 0, 
	end = 0,
	mn_begin = -1,
	mn_end = -1,
	begin_i = 0,
	end_i = 0;

	for (; begin <= INF; begin++) {

		while ((end <= INF && curr < H) || begin == end) {
			while (begin_i < N && beginS[begin_i] == end) {
				begin_i++;
				curr++;
			}
			end++;
		}

		if (H <= curr && (mn_begin == -1 || end - begin < mn_end - mn_begin)) {
			mn_begin = begin;
			mn_end = end;
		}

		while (end_i < N && endS[end_i] == begin) {
			end_i++;
			curr--;
		}
	}

	cout 
	<< mn_end - mn_begin << '\n' 
	<< mn_begin << ' ' << mn_end - 1; 
}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/03ms1832 KiB
2Accepted0/037ms3516 KiB
3Accepted2/23ms2596 KiB
4Accepted2/23ms2556 KiB
5Accepted2/23ms2784 KiB
6Accepted2/23ms2908 KiB
7Accepted2/23ms3264 KiB
8Accepted3/33ms3012 KiB
9Accepted3/33ms3012 KiB
10Accepted3/33ms3160 KiB
11Accepted3/34ms3064 KiB
12Accepted3/36ms3248 KiB
13Accepted3/36ms3468 KiB
14Accepted3/38ms3608 KiB
15Accepted3/38ms3612 KiB
16Accepted3/38ms3628 KiB
17Accepted3/38ms3624 KiB
18Accepted3/313ms3768 KiB
19Accepted3/329ms4852 KiB
20Accepted3/326ms4900 KiB
21Accepted3/335ms5052 KiB
22Accepted3/335ms4908 KiB