201882026-01-04 13:30:58algoproSíkság (55)cpp17Accepted 55/5534ms800 KiB
// UUID: e5b60cbd-bb1f-48c9-b457-89a1e96b4f81
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n;
    cin >> n;
    vector<int> h(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> h[i];
    }
    int other = -1, start = 1, same_start = 1, best_start = 1, max_len = 1;
    for (int i = 2; i <= n; i++) {
        if (h[i] != h[i - 1]) {
            if (h[i] == other) {
                other = h[i - 1];
                same_start = i;
            } else if (abs(h[i] - h[i - 1]) == 1) {
                other = h[i - 1];
                start = same_start;
                same_start = i;
            } else {
                start = same_start = i;
                other = -1;
            }
        }
        if (i - start + 1 > max_len) {
            max_len = i - start + 1;
            best_start = start;
        }
    }
    
    cout << max_len << " " << best_start;
}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/01ms316 KiB
2Accepted0/03ms316 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms316 KiB
7Accepted3/31ms316 KiB
8Accepted2/21ms508 KiB
9Accepted3/31ms316 KiB
10Accepted3/34ms432 KiB
11Accepted3/33ms316 KiB
12Accepted3/33ms440 KiB
13Accepted3/330ms564 KiB
14Accepted3/318ms800 KiB
15Accepted3/324ms588 KiB
16Accepted3/332ms796 KiB
17Accepted3/334ms564 KiB
18Accepted3/332ms564 KiB
19Accepted3/332ms564 KiB
20Accepted3/332ms796 KiB
21Accepted3/317ms564 KiB
22Accepted3/326ms564 KiB