103822024-04-01 17:47:03MagyarKendeSZLGLegtöbbször szomszédok (75 pont)cpp17Wrong answer 0/7514ms7620 KiB
#include <bits/stdc++.h>
using namespace std;

constexpr int INF = 1e4 + 1;

int main() {
	cin.tie(0), ios::sync_with_stdio(0);

    int N, M;
    cin >> N >> M;
    M--;

    vector<int> v(N);
    for (int& x : v) cin >> x;

    vector<array<int, 2>> befS({{INF, -1}}), aftS({{-INF, -1}});

    for (int i = 0; i < M; i++) {
        if (v[i] > v[M] && v[i] < befS.back()[0]) {
            befS.back() = {v[i], i};
        }
        else if (v[i] < v[M] && v[i] > aftS.back()[0]) {
            aftS.back() = {v[i], i};
        }
    }

    for (int i = M + 1; i < N; i++) {
        if (v[i] > v[M] && v[i] < befS.back()[0]) {
            befS.push_back({v[i], i});
        }
        else if (v[i] < v[M] && v[i] > aftS.back()[0]) {
            aftS.push_back({v[i], i});
        }
    }

    befS.push_back({INF, N});
    aftS.push_back({INF, N});

    for (auto [score, id] : befS) {
        cout << score << " " << id << "\n";
    }
    cout << "\n";
    for (auto [score, id] : aftS) {
        cout << score << " " << id << "\n";
    }
    cout << "\n";

    int p1 = -1, p1_i = -1;
    for (int i = 0; i < size(befS) - 1; i++) {
        if (befS[i][0] == INF) continue;
        int val = befS[i + 1][1] - max(befS[i][1], M);
        if (p1 < val) {
            p1 = val;
            p1_i = befS[i][1];
        }
    }

    if (p1 == -1) {
        cout << "-1\n";
    } else {
        cout << p1_i + 1 << " " << p1 << "\n";
    }

    int p2 = -1, p2_i = -1;
    for (int i = 0; i < size(aftS) - 1; i++) {
        if (abs(aftS[i][0]) == INF) continue;
        int val = aftS[i + 1][1] - max(aftS[i][1], M);
        if (p2 < val) {
            p2 = val;
            p2_i = aftS[i][1];
        }
    }

    if (p2 == -1) {
        cout << "-1";
    } else {
        cout << p2_i + 1 << " " << p2;
    }
}
SubtaskSumTestVerdictTimeMemory
base0/75
1Wrong answer0/03ms1976 KiB
2Wrong answer0/013ms3380 KiB
3Wrong answer0/23ms2704 KiB
4Wrong answer0/23ms2920 KiB
5Wrong answer0/43ms3148 KiB
6Wrong answer0/43ms3312 KiB
7Wrong answer0/33ms3404 KiB
8Wrong answer0/43ms3408 KiB
9Wrong answer0/43ms3532 KiB
10Wrong answer0/44ms3624 KiB
11Wrong answer0/44ms3808 KiB
12Wrong answer0/44ms4040 KiB
13Wrong answer0/44ms4116 KiB
14Wrong answer0/44ms4408 KiB
15Wrong answer0/44ms4548 KiB
16Wrong answer0/46ms4820 KiB
17Wrong answer0/47ms5016 KiB
18Wrong answer0/48ms5088 KiB
19Wrong answer0/414ms6232 KiB
20Wrong answer0/414ms6580 KiB
21Wrong answer0/414ms6972 KiB
22Wrong answer0/414ms7620 KiB