42682023-03-20 22:40:42xxxLegtöbbször szomszédok (75 pont)cpp14Partially correct 73/7532ms4908 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;
    for (int i = 0; i < n; i++) {
        if (a[i] > lo && a[i] < elott) {
            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) {
            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;
    }

    cout << emi+1 << " " << emax << endl << umi+1 << " " << umax << endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base73/75
1Accepted0/03ms2020 KiB
2Accepted0/028ms2992 KiB
3Partially correct1/23ms2356 KiB
4Partially correct1/23ms2592 KiB
5Accepted4/43ms2648 KiB
6Accepted4/43ms2884 KiB
7Accepted3/33ms3068 KiB
8Accepted4/43ms3308 KiB
9Accepted4/44ms3352 KiB
10Accepted4/44ms3524 KiB
11Accepted4/44ms3660 KiB
12Accepted4/48ms3784 KiB
13Accepted4/48ms3708 KiB
14Accepted4/48ms3708 KiB
15Accepted4/48ms3720 KiB
16Accepted4/410ms4028 KiB
17Accepted4/414ms4104 KiB
18Accepted4/417ms4504 KiB
19Accepted4/428ms4908 KiB
20Accepted4/428ms4812 KiB
21Accepted4/428ms4812 KiB
22Accepted4/432ms4812 KiB