35042023-02-28 13:45:00EyusieTalálkozáscpp17Time limit exceeded 52/55261ms7720 KiB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

struct interv
{
    int k;
    bool ki;
};
bool comp(interv a, interv b)
{
    return a.k == b.k ? a.ki : a.k < b.k;
}
int main()
{
    int n;
    cin >> n;
    vector<interv> ember(2*n);
    set<int> egysz;
    string asd;
    int mx = 0;
    bool swp = true;
    for(int i = 0; i < 2*n; i+=2)
    {
        cin >> ember[i].k;
        ember[i].ki = true;
        if(ember[i].k > mx) mx = ember[i].k;
        cin >> ember[i+1].k;
        ember[i+1].ki = false;
}
    int fel;
    if(n%2 == 1) fel = n/2 + 1;
    else fel = n/2;
    int szamlalo = 0;
    int hossz = 999999999;
    int van = 0;
    int legkh = 999999999;
    int u = 0, v = -1;
    int kezdet = 0;
    sort(ember.begin(), ember.end(), comp);
    while(v < 2*n)
    {
        while(szamlalo < fel && v != 2*n)
        {
            v++;
            if(ember[v].ki) szamlalo++;
        }
        if(v == 2*n) break;
        while(ember[u].ki && u < v) u++;
        hossz = ember[v].k-ember[u].k;
        if(hossz < legkh)
        {
            legkh = hossz;
            kezdet = ember[u].k;
        }
        u++;
        szamlalo--;
    }
    cout << legkh+1 << "\n" << kezdet << " " << kezdet+legkh;
}
SubtaskSumTestVerdictTimeMemory
base52/55
1Accepted0/03ms1808 KiB
2Accepted0/089ms5096 KiB
3Accepted2/23ms2272 KiB
4Accepted2/23ms2480 KiB
5Accepted2/23ms2640 KiB
6Accepted2/23ms2888 KiB
7Accepted2/23ms3072 KiB
8Accepted3/33ms3172 KiB
9Accepted3/33ms3400 KiB
10Accepted3/33ms3500 KiB
11Accepted3/37ms3844 KiB
12Accepted3/39ms3876 KiB
13Accepted3/39ms3880 KiB
14Accepted3/317ms4264 KiB
15Accepted3/317ms4308 KiB
16Accepted3/317ms4508 KiB
17Accepted3/317ms4604 KiB
18Accepted3/327ms5008 KiB
19Accepted3/382ms7472 KiB
20Time limit exceeded0/3261ms5472 KiB
21Accepted3/389ms7660 KiB
22Accepted3/389ms7720 KiB