78962024-01-11 18:31:42AblablablaLegtöbbször szomszédok (75 pont)cpp17Partially correct 73/7535ms9568 KiB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;

    vector<int> pontok(n, 0);

    for(int i = 0; i < n; i++){
        cin >> pontok[i];
    }

    int lo = pontok[k - 1];
    int elotteInd = 0;
    int mogottInd = 0;
    int elotte = 2e9 + 7;
    int mogotte = -1;

    for(int i = 0; i < k; i++){
        if(lo > pontok[i]){
            if(pontok[i] > mogotte){
                mogotte = pontok[i];
                mogottInd = i;
            }
        } else if(pontok[i] > lo){
            if(elotte > pontok[i]){
                elotte = pontok[i];
                elotteInd = i;
            }
        }
    }

    vector<int> elol(n, 0);
    vector<int> hatul(n, 0);

    elol[elotteInd]++;
    hatul[mogottInd]++;

    for(int i = k; i < n; i++){
        if(lo > pontok[i]){
            if(pontok[i] > mogotte){
                mogotte = pontok[i];
                mogottInd = i;
            }
        } else if(pontok[i] > lo){
            if(elotte > pontok[i]){
                elotte = pontok[i];
                elotteInd = i;
            }
        }

        elol[elotteInd]++;
        hatul[mogottInd]++;
    }

    int maxi = 0;
    int maxInd = 0;
    for(int i = 0; i < n; i++){
        if(maxi < elol[i]){
            maxi = elol[i];
            maxInd = i;
        }
    }

    if(maxi != 0){
        cout << maxInd + 1 << " " << maxi << "\n";
    } else{
        cout << "-1\n";
    }

    maxi = 0;
    maxInd = 0;
    for(int i = 0; i < n; i++){
        if(maxi < hatul[i]){
            maxi = hatul[i];
            maxInd = i;
        }
    }

    if(maxi != 0){
        cout << maxInd + 1 << " " << maxi << "\n";
    } else{
        cout << "-1\n";
    }
}
SubtaskSumTestVerdictTimeMemory
base73/75
1Accepted0/03ms1812 KiB
2Accepted0/029ms4836 KiB
3Partially correct1/23ms2668 KiB
4Partially correct1/23ms2884 KiB
5Accepted4/43ms3128 KiB
6Accepted4/43ms3316 KiB
7Accepted3/33ms3428 KiB
8Accepted4/43ms3536 KiB
9Accepted4/44ms3948 KiB
10Accepted4/46ms4376 KiB
11Accepted4/46ms4344 KiB
12Accepted4/48ms4964 KiB
13Accepted4/48ms5056 KiB
14Accepted4/48ms5216 KiB
15Accepted4/48ms5500 KiB
16Accepted4/412ms5684 KiB
17Accepted4/414ms6192 KiB
18Accepted4/418ms6680 KiB
19Accepted4/432ms8380 KiB
20Accepted4/430ms8768 KiB
21Accepted4/432ms9112 KiB
22Accepted4/435ms9568 KiB