78972024-01-11 18:36:34AblablablaLegtöbbször szomszédok (75 pont)cpp17Accepted 75/7532ms6724 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 - 1; 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);

    if(elotte != 2e9 + 7){
        elol[elotteInd]++;
    }
    if(mogotte != -1){
        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;
            }
        }

        if(elotte != 2e9 + 7){
            elol[elotteInd]++;
        }
        if(mogotte != -1){
            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
base75/75
1Accepted0/03ms1812 KiB
2Accepted0/028ms4320 KiB
3Accepted2/23ms2364 KiB
4Accepted2/23ms2348 KiB
5Accepted4/43ms2544 KiB
6Accepted4/43ms2796 KiB
7Accepted3/33ms3156 KiB
8Accepted4/43ms3212 KiB
9Accepted4/44ms3640 KiB
10Accepted4/44ms3584 KiB
11Accepted4/44ms3772 KiB
12Accepted4/48ms3868 KiB
13Accepted4/48ms4152 KiB
14Accepted4/48ms4064 KiB
15Accepted4/48ms4224 KiB
16Accepted4/410ms4696 KiB
17Accepted4/414ms4900 KiB
18Accepted4/417ms5028 KiB
19Accepted4/429ms6544 KiB
20Accepted4/429ms6652 KiB
21Accepted4/429ms6724 KiB
22Accepted4/432ms6528 KiB