69692023-12-22 15:57:50MagyarKendeSZLGTalálkozáscpp17Time limit exceeded 38/55300ms4720 KiB
#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <climits>
#include <algorithm>
#include <numeric>

using namespace std;

#define speed cin.tie(0); ios::sync_with_stdio(0)

const int INF = 100'001;

int main()
{
	speed;

	int N, H;
	cin >> N;

	H = N / 2 + (N & 1);
	
	vector<int> eS(N);
	vector<int> vS(N);

	for (int i = 0; i < N; i++) {
		int E, V;
		cin >> E >> V;
		eS[i] = E;
		vS[i] = V;
	}

	std::sort(eS.begin(), eS.end());
	std::sort(vS.begin(), vS.end());

	array<int, 2> min_v{ 0, INF };

	for (int i = 0; i < N; i++) {

		int e = vS[i],
			v = eS.back(),
			curr = N - i + 1,
			j = N;

		while (e < v && H < curr) {

			v = eS[--j];
			
			curr--;

			// cerr << vS[i] << ", " << curr << " : " << e << ' ' << v << '\n';

			if (v - e < min_v[1] - min_v[0]) {
				min_v = { e, v };
			}
		}
	}
	
	// cerr << '\n';

	cout << min_v[1] - min_v[0] + 1 << '\n' << min_v[0] << ' ' << min_v[1];
}
SubtaskSumTestVerdictTimeMemory
base38/55
1Accepted0/03ms1828 KiB
2Time limit exceeded0/0300ms2220 KiB
3Wrong answer0/23ms2268 KiB
4Accepted2/23ms2440 KiB
5Accepted2/23ms2528 KiB
6Accepted2/23ms2524 KiB
7Accepted2/23ms2656 KiB
8Accepted3/33ms2740 KiB
9Accepted3/33ms3004 KiB
10Accepted3/33ms3004 KiB
11Accepted3/314ms3160 KiB
12Accepted3/329ms3408 KiB
13Accepted3/330ms3300 KiB
14Accepted3/3107ms3476 KiB
15Accepted3/3108ms3584 KiB
16Accepted3/398ms3380 KiB
17Accepted3/3103ms3380 KiB
18Time limit exceeded0/3270ms2652 KiB
19Wrong answer0/328ms4464 KiB
20Wrong answer0/325ms4720 KiB
21Time limit exceeded0/3300ms3736 KiB
22Time limit exceeded0/3270ms3700 KiB