223422026-01-14 21:42:18gkataTalálkozáscpp17Elfogadva 55/5525ms1260 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, mhossz, fel, p1, p2, jobb, bal;
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 + 1) / 2;

    bal = 1;
    jobb = mt;
    mhossz = mt;
    for (jobb = 1; jobb <= mt; ++jobb)
    {
        while (bal <= jobb && erk[jobb] - tav[bal - 1] >= fel)
        {
            hossz = jobb - bal;
            if (hossz < mhossz)
            {
                mhossz = hossz;
                p1 = bal;
                p2 = jobb;
            }
            ++bal;
        }
    }

    cout << mhossz + 1 << endl << p1 << " " << p2;
}

/*
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
RészfeladatÖsszpontTesztVerdiktIdőMemória
base55/55
1Elfogadva0/02ms1076 KiB
2Elfogadva0/024ms1076 KiB
3Elfogadva2/22ms1076 KiB
4Elfogadva2/22ms1076 KiB
5Elfogadva2/21ms1076 KiB
6Elfogadva2/22ms1076 KiB
7Elfogadva2/22ms1076 KiB
8Elfogadva3/32ms1076 KiB
9Elfogadva3/32ms1076 KiB
10Elfogadva3/32ms1260 KiB
11Elfogadva3/33ms1076 KiB
12Elfogadva3/34ms1076 KiB
13Elfogadva3/34ms1076 KiB
14Elfogadva3/36ms1228 KiB
15Elfogadva3/36ms1076 KiB
16Elfogadva3/36ms1076 KiB
17Elfogadva3/36ms1224 KiB
18Elfogadva3/38ms1076 KiB
19Elfogadva3/324ms1216 KiB
20Elfogadva3/321ms1076 KiB
21Elfogadva3/325ms1224 KiB
22Elfogadva3/324ms1216 KiB