42692023-03-20 22:43:28xxxLegtöbbször szomszédok (75 pont)cpp14Accepted 75/7532ms5124 KiB
#include <bits/stdc++.h>
using namespace std;


int main() {
    int n, m;
    cin >> n >> m;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int lo = a[m-1];
    int elott = INT_MAX, utan = 0, ei, ui;
    int elottcnt = 0, utancnt = 0;
    int emax = 0, umax = 0, emi, umi;
    bool volte = false, voltu = false;
    for (int i = 0; i < n; i++) {
        if (a[i] > lo && a[i] < elott) {
            volte = true;
            if (i >= m-1) {
                if (elottcnt > emax) {
                    emax = elottcnt;
                    emi = ei;
                }
                elottcnt = 1;
            }
            elott = a[i];
            ei = i;
        } else if (i >= m-1) {
            elottcnt++;
        }
        if (a[i] < lo && a[i] > utan) {
            voltu = true;
            if (i >= m-1) {
                if (utancnt > umax) {
                    umax = utancnt;
                    umi = ui;
                }
                utancnt = 1;
            }
            utan = a[i];
            ui = i;

        } else if (i >= m-1) {
            utancnt++;
        }
    }
    if (elottcnt > emax) {
        emax = elottcnt;
        emi = ei;
    }

    if (utancnt > umax) {
        umax = utancnt;
        umi = ui;
    }
    if (!volte) {cout << -1 << endl;} else
    cout << emi+1 << " " << emax << endl;

    if (!voltu) {cout << -1 << endl;} else
    cout << umi+1 << " " << umax << endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/03ms1876 KiB
2Accepted0/027ms2892 KiB
3Accepted2/23ms2332 KiB
4Accepted2/23ms2488 KiB
5Accepted4/43ms2704 KiB
6Accepted4/43ms2912 KiB
7Accepted3/33ms3132 KiB
8Accepted4/43ms3216 KiB
9Accepted4/44ms3356 KiB
10Accepted4/44ms3456 KiB
11Accepted4/44ms3584 KiB
12Accepted4/48ms3960 KiB
13Accepted4/48ms3916 KiB
14Accepted4/48ms3956 KiB
15Accepted4/48ms4108 KiB
16Accepted4/410ms4084 KiB
17Accepted4/414ms4180 KiB
18Accepted4/417ms4164 KiB
19Accepted4/428ms4676 KiB
20Accepted4/428ms4808 KiB
21Accepted4/428ms4884 KiB
22Accepted4/432ms5124 KiB