130522025-01-05 12:18:24szabelrTalálkozáscpp17Hibás válasz 50/5568ms1188 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 << joe << endl;
        //cout << "veg:" << veg << " kez:" << kez << endl;
        if (veg - kez < db and joe==1) {
            db = veg - kez;
            kezjo = kez;
            vegjo = veg;
        }
        ossz = ossz-tav[kez];
        //cout << "ossz:" << ossz << endl;
        kez++;
        
    }
    cout << db+1 << 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
base50/55
1Elfogadva0/01ms320 KiB
2Elfogadva0/064ms1080 KiB
3Hibás válasz0/21ms508 KiB
4Elfogadva2/21ms508 KiB
5Elfogadva2/21ms320 KiB
6Elfogadva2/21ms320 KiB
7Elfogadva2/21ms320 KiB
8Elfogadva3/31ms320 KiB
9Elfogadva3/31ms320 KiB
10Elfogadva3/31ms320 KiB
11Elfogadva3/34ms568 KiB
12Elfogadva3/37ms656 KiB
13Elfogadva3/37ms608 KiB
14Elfogadva3/313ms568 KiB
15Elfogadva3/313ms732 KiB
16Elfogadva3/312ms776 KiB
17Elfogadva3/313ms636 KiB
18Elfogadva3/320ms1188 KiB
19Hibás válasz0/367ms784 KiB
20Elfogadva3/359ms416 KiB
21Elfogadva3/364ms1080 KiB
22Elfogadva3/368ms1080 KiB