130572025-01-05 12:30:32szabelrTalálkozáscpp17Elfogadva 55/5567ms1176 KiB
// Találkozás.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
using namespace std;
int erk[100001]{ 0 };
int tav[100001]{ 0 };
int main()
{
    int n, max=0,a,b;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a >> b;
        erk[a]++;
        tav[b]++;
        if (b > max)
            max=b;
        
    }
    /*for (int i = 1; i <= max; i++) {
        cout << erk[i] << " ";
    }
    cout << endl;
    for (int i = 1; i <= max; i++) {
        cout << tav[i] << " ";
    }*/
    int kez = 1, veg=0, ossz = 0,kezjo,vegjo,db=1000001,joe=1;
    while (kez <= max) {
        while (ossz < ((n + 1) / 2) && veg < max) {
            veg++;
            ossz += erk[veg];                
        }
        if (veg == max and ossz < (n + 1) / 2) {
            joe = 0;
        }
        //cout << "veg:" << veg << " kez:" << kez << endl;
        //cout << joe << endl;
        if (veg - kez+1 < db and joe==1 and veg-kez+1>0) {
            db = veg - kez+1;
            kezjo = kez;
            vegjo = veg;
        }
        ossz = ossz-tav[kez];
        //cout << "ossz:" << ossz << endl;
        kez++;
        
    }
    cout << db << endl;
    cout << kezjo << " " << vegjo;

}

// 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/01ms320 KiB
2Elfogadva0/064ms1060 KiB
3Elfogadva2/21ms552 KiB
4Elfogadva2/21ms320 KiB
5Elfogadva2/21ms320 KiB
6Elfogadva2/21ms376 KiB
7Elfogadva2/21ms320 KiB
8Elfogadva3/31ms320 KiB
9Elfogadva3/31ms388 KiB
10Elfogadva3/31ms320 KiB
11Elfogadva3/34ms580 KiB
12Elfogadva3/37ms568 KiB
13Elfogadva3/37ms764 KiB
14Elfogadva3/313ms744 KiB
15Elfogadva3/312ms756 KiB
16Elfogadva3/312ms580 KiB
17Elfogadva3/312ms788 KiB
18Elfogadva3/320ms968 KiB
19Elfogadva3/367ms568 KiB
20Elfogadva3/359ms420 KiB
21Elfogadva3/364ms1176 KiB
22Elfogadva3/364ms1048 KiB