147452025-01-31 16:29:58miszorimarciLegtöbbször szomszédok (75 pont)cpp17Accepted 75/7529ms804 KiB
#include <bits/stdc++.h>
using namespace std;


int main() {
    int n, m;
    cin >> n >> m;
    vector<int>a(n);
    for(int &i : a)cin >> i;
    int lo = a[m-1];
    int bef = INT_MAX, aft = 0, bef_i, aft_i;
    int befcnt = 0, aftcnt = 0;
    int befmax = 0, aftmax = 0, befmi, aftmi;
    bool volte = false, voltu = false;
    for (int i = 0; i < n; i++) {
        if (a[i] > lo && a[i] < bef) {
            volte = true;
            if (i >= m-1) {
                if (befcnt > befmax) {
                    befmax = befcnt;
                    befmi = bef_i;
                }
                befcnt = 1;
            }
            bef = a[i];
            bef_i = i;
        } else if (i >= m-1) {
            befcnt++;
        }
        if (a[i] < lo && a[i] > aft) {
            voltu = true;
            if (i >= m-1) {
                if (aftcnt > aftmax) {
                    aftmax = aftcnt;
                    aftmi = aft_i;
                }
                aftcnt = 1;
            }
            aft = a[i];
            aft_i = i;

        } else if (i >= m-1) {
            aftcnt++;
        }
    }
    if (befcnt > befmax) {
        befmax = befcnt;
        befmi = bef_i;
    }
    if (aftcnt > aftmax) {
        aftmax = aftcnt;
        aftmi = aft_i;
    }
    if (!volte) {cout << -1 << endl;} else cout << befmi+1 << " " << befmax << endl;
    if (!voltu) {cout << -1 << endl;} else cout << aftmi+1 << " " << aftmax << endl;
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/01ms548 KiB
2Accepted0/026ms564 KiB
3Accepted2/21ms508 KiB
4Accepted2/21ms316 KiB
5Accepted4/41ms316 KiB
6Accepted4/41ms316 KiB
7Accepted3/31ms316 KiB
8Accepted4/41ms316 KiB
9Accepted4/43ms356 KiB
10Accepted4/44ms536 KiB
11Accepted4/44ms316 KiB
12Accepted4/46ms316 KiB
13Accepted4/46ms316 KiB
14Accepted4/46ms316 KiB
15Accepted4/46ms468 KiB
16Accepted4/49ms512 KiB
17Accepted4/412ms568 KiB
18Accepted4/416ms604 KiB
19Accepted4/427ms800 KiB
20Accepted4/427ms796 KiB
21Accepted4/427ms800 KiB
22Accepted4/429ms804 KiB