18752022-12-06 20:59:26kovacs.peter.18fSíkság (55)cpp11Accepted 55/5516ms4724 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.begin())->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/03ms2192 KiB
3Accepted2/22ms2100 KiB
4Accepted2/22ms2316 KiB
5Accepted2/22ms2424 KiB
6Accepted2/22ms2628 KiB
7Accepted3/32ms2704 KiB
8Accepted2/22ms2712 KiB
9Accepted3/32ms2716 KiB
10Accepted3/33ms3012 KiB
11Accepted3/33ms2960 KiB
12Accepted3/33ms3084 KiB
13Accepted3/316ms4040 KiB
14Accepted3/310ms4116 KiB
15Accepted3/313ms4236 KiB
16Accepted3/314ms4312 KiB
17Accepted3/314ms4312 KiB
18Accepted3/316ms4512 KiB
19Accepted3/314ms4724 KiB
20Accepted3/314ms4720 KiB
21Accepted3/38ms4456 KiB
22Accepted3/310ms4528 KiB