213132026-01-12 18:21:43PappMatyasTalálkozáscpp17Accepted 55/5568ms1268 KiB
#include <iostream>
#include <vector>

using namespace std;

const int maxLength = 100000;

int main()
{
	int n;
	vector<int> starts(maxLength, 0);
	vector<int> ends(maxLength, 0);

	cin >> n;

	int lastDay = 0;

	for (int i = 0; i < n; i++)
	{
		int s, e;
		cin >> s >> e;
		starts[s - 1]++;
		ends[e - 1]++;
		lastDay = max(lastDay, e);
	}

	int ce = 0, total = starts[0];

	int minimum = maxLength + 1;

	int se = -1;
	int ss = -1;

	float threshold = float(n) / 2;

	for (int i = 0; i < lastDay; i++)
	{
		while (total < threshold && ce < lastDay - 1)
		{
			ce++;
			total += starts[ce];
		}
		if (ce - i + 1 < minimum && total >= threshold && ce - i + 1 > 0)
		{
			minimum = ce - i + 1;
			se = ce + 1;
			ss = i + 1;
		}
		total -= ends[i];
	}

	cout << minimum << endl << ss << " " << se << endl;

	return 0;
}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/02ms1268 KiB
2Accepted0/067ms1076 KiB
3Accepted2/22ms1076 KiB
4Accepted2/22ms1076 KiB
5Accepted2/22ms1076 KiB
6Accepted2/22ms1076 KiB
7Accepted2/23ms1076 KiB
8Accepted3/32ms1132 KiB
9Accepted3/32ms1076 KiB
10Accepted3/32ms1076 KiB
11Accepted3/37ms1080 KiB
12Accepted3/38ms1084 KiB
13Accepted3/38ms1096 KiB
14Accepted3/313ms1192 KiB
15Accepted3/314ms1200 KiB
16Accepted3/313ms1200 KiB
17Accepted3/313ms1196 KiB
18Accepted3/321ms1076 KiB
19Accepted3/368ms976 KiB
20Accepted3/361ms1152 KiB
21Accepted3/365ms1200 KiB
22Accepted3/367ms1124 KiB