18762022-12-06 21:02:09kovacs.peter.18fSíkság (55)cpp11Accepted 55/5516ms4656 KiB
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main() {
    cin.sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    vector<int> heightS(N);
    map<int, int> countS;
    int different = 0, max_begin = 0, max_end = 0;
    for (int l = 0, r = 0; r < N; r++) { // zárt intervallum
        cin >> heightS[r];
        if (++countS[heightS[r]] == 1) {
            ++different;
        }
        while (different == 3) {
            if (--countS[heightS[l]] == 0) {
                --different;
                countS.erase(heightS[l]);
            }
            ++l;
        }
        if (abs(countS.begin()->first - countS.rbegin()->first) != 1) {
            while (different == 2) {
                if (--countS[heightS[l]] == 0) {
                    --different;
                    countS.erase(heightS[l]);
                }
                ++l;
            }
        }
        if (r - l > max_end - max_begin) {
            max_begin = l;
            max_end = r;
        }
    }
    cout << max_end - max_begin + 1 << " " << max_begin + 1 << '\n';
}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/03ms1824 KiB
2Accepted0/03ms2236 KiB
3Accepted2/22ms2264 KiB
4Accepted2/22ms2432 KiB
5Accepted2/22ms2632 KiB
6Accepted2/22ms2704 KiB
7Accepted3/32ms2940 KiB
8Accepted2/22ms3048 KiB
9Accepted3/32ms3252 KiB
10Accepted3/33ms3360 KiB
11Accepted3/33ms3364 KiB
12Accepted3/33ms3364 KiB
13Accepted3/314ms4008 KiB
14Accepted3/310ms4136 KiB
15Accepted3/313ms4340 KiB
16Accepted3/314ms4460 KiB
17Accepted3/314ms4536 KiB
18Accepted3/316ms4616 KiB
19Accepted3/314ms4544 KiB
20Accepted3/314ms4500 KiB
21Accepted3/38ms4320 KiB
22Accepted3/310ms4656 KiB