220342026-01-14 13:39:19gkataTalálkozáscpp17Time limit exceeded 25/55300ms1268 KiB
// talalkozas.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <queue>
#define ll long long

using namespace std;

vector<int>erk(100000);
vector<int>tav(100000);

ll i, n, a, b, mt = -1, hossz, fel, poz;
bool ok = false;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n;

    for (i = 1; i <= n; ++i)
    {
        cin >> a >> b;
        ++erk[a];
        ++tav[b];
        if (b > mt) mt = b;
    }

    for (i = 1; i <= mt; ++i)
    {
        erk[i] += erk[i - 1];
        tav[i] += tav[i - 1];
    }

    fel = n / 2 + n % 2;
    for (hossz = 1; hossz <= mt; ++hossz)
    {
        for (i = hossz; i <= mt; ++i)
        {
            if (erk[i] - tav[i - hossz] >= fel)
            {
                poz = i;
                ok = true;
                break;
            }
        }
        if (ok) break;
    }

    cout << hossz << endl << poz - hossz + 1 << " " << poz;
}

/*
6
1 5
2 3
5 9
7 8
10 15
10 18
*/
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
base25/55
1Accepted0/01ms1076 KiB
2Time limit exceeded0/0282ms1076 KiB
3Accepted2/21ms1076 KiB
4Accepted2/22ms1080 KiB
5Accepted2/21ms1076 KiB
6Accepted2/29ms1220 KiB
7Accepted2/210ms1076 KiB
8Accepted3/38ms1076 KiB
9Accepted3/335ms1076 KiB
10Accepted3/334ms1216 KiB
11Time limit exceeded0/3300ms1136 KiB
12Time limit exceeded0/3286ms1076 KiB
13Time limit exceeded0/3286ms1268 KiB
14Time limit exceeded0/3280ms1076 KiB
15Time limit exceeded0/3282ms1076 KiB
16Time limit exceeded0/3286ms1200 KiB
17Time limit exceeded0/3287ms1172 KiB
18Time limit exceeded0/3280ms1076 KiB
19Accepted3/321ms1076 KiB
20Accepted3/319ms1076 KiB
21Time limit exceeded0/3293ms1076 KiB
22Time limit exceeded0/3300ms1076 KiB