25472023-01-16 22:29:24SleepyOverlordTalálkozáscpp17Accepted 55/5568ms5548 KiB
#include <vector>
#include <string> 
#include <set> 
#include <map> 
#include <unordered_set>
#include <unordered_map>
#include <queue> 
#include <bitset> 
#include <stack>
#include <list>

#include <numeric> 
#include <algorithm> 
#include <random>
#include <chrono>

#include <cstdio>
#include <fstream>
#include <iostream> 
#include <sstream> 
#include <iomanip>
#include <climits>

#include <cctype>
#include <cmath> 
#include <ctime>
#include <cassert>

using namespace std;

#define ULL unsigned long long
#define LL long long
#define PII pair <int, int>
#define VB vector <bool>
#define VI vector <int>
#define VLL vector <LL>
#define VD vector <double>
#define VS vector <string>
#define VPII vector <pair <int, int> >
#define VVI vector < VI >
#define VVB vector < VB >
#define SI set < int >
#define USI unordered_set <int>
#define MII map <int, int>
#define UMII unordered_map <int, int>
#define MS multiset
#define US unordered_set
#define UM unordered_map
#define UMS unordered_multiset
#define UMM unordered_multimap

#define FORN(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)

#define SZ size()
#define BG begin() 
#define EN end() 
#define CL clear()
#define X first
#define Y second
#define RS resize
#define PB push_back
#define ALL(x) x.begin(), x.end()
#define INS insert
#define ER erase
#define CNT count

#define IN_FILE "a.in"
#define OUT_FILE "a.out"

template <typename T>
void PR(T var1)
{
	cout << var1 <<endl;
}
template <typename T, typename... Types>
void PR(T var1, Types... var2)
{
	cout << var1;
	PR(var2...);
}

#define MAX 100000

int n;
VI start(MAX + 1), stop(MAX + 1);

int meet(int l, int r)
{
	if (l > r) return 0;
	return start[l] - stop[l - 1] + start[r] - start[l];
}

int main()
{
	cin >> n;
	FOR(i, 1, n)
	{
		int x, y;
		cin >> x >> y;
		++start[x];
		++stop[y];
	}
	FOR(i, 1, MAX)
	{
		start[i] += start[i - 1];
		stop[i] += stop[i - 1];
	}
	int bestl = -1, bestr = -1, half = (n + 1) / 2;
	int l = 1, r = 1;
	while (r <= MAX)
	{
		while(r <= MAX && (meet(l, r) < half)) ++r;
		if (r > MAX) break;
		while (l <= r && (meet(l, r) >= half)) ++l;
		if (bestl == -1 || bestr - bestl > r - l)
		{
			bestl = l;
			bestr = r;
		}
	}
	PR(bestr - bestl + 2);
	PR(bestl - 1, " ", bestr);

	return 0;
}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/04ms3204 KiB
2Accepted0/065ms3396 KiB
3Accepted2/23ms3528 KiB
4Accepted2/23ms3708 KiB
5Accepted2/23ms3912 KiB
6Accepted2/23ms4116 KiB
7Accepted2/23ms4320 KiB
8Accepted3/33ms4524 KiB
9Accepted3/33ms4744 KiB
10Accepted3/33ms4748 KiB
11Accepted3/37ms4732 KiB
12Accepted3/38ms4864 KiB
13Accepted3/38ms4952 KiB
14Accepted3/314ms4936 KiB
15Accepted3/314ms5064 KiB
16Accepted3/314ms5280 KiB
17Accepted3/316ms5348 KiB
18Accepted3/321ms5348 KiB
19Accepted3/368ms5348 KiB
20Accepted3/359ms5352 KiB
21Accepted3/365ms5476 KiB
22Accepted3/367ms5548 KiB