90922024-02-13 20:15:03RRoliSíkság (55)cpp17Accepted 55/5539ms4824 KiB
#include <iostream>
#include <set>

using namespace std;

int n, a[100001], sz[100001], maxi_l = 1, maxi_r = 1;
set<int> van;

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];

    int l = 1;
	van.insert(a[1]);
    sz[a[1]]++;

    for(int r = 2; r <= n; r++) {
        sz[a[r]]++;
		van.insert(a[r]);
		set<int> torol;
		for(int i : van) {
			if(abs(a[r] - i) > 1) {
				while(sz[i] != 0) {
					l++;
					sz[a[l-1]]--;
				}
				torol.insert(i);
			}
		}
		for(int i : torol) van.erase(i); 
		if(r-l > maxi_r-maxi_l) {maxi_r = r; maxi_l = l;}
    }

	cout << maxi_r-maxi_l+1 << ' ' << maxi_l;

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/03ms1820 KiB
2Accepted0/06ms2224 KiB
3Accepted2/23ms2224 KiB
4Accepted2/23ms2340 KiB
5Accepted2/23ms2416 KiB
6Accepted2/23ms2540 KiB
7Accepted3/33ms2752 KiB
8Accepted2/23ms2848 KiB
9Accepted3/33ms2840 KiB
10Accepted3/36ms3228 KiB
11Accepted3/34ms3340 KiB
12Accepted3/34ms3300 KiB
13Accepted3/337ms4344 KiB
14Accepted3/321ms4368 KiB
15Accepted3/328ms4460 KiB
16Accepted3/337ms4572 KiB
17Accepted3/337ms4824 KiB
18Accepted3/339ms4800 KiB
19Accepted3/337ms4776 KiB
20Accepted3/337ms4776 KiB
21Accepted3/321ms4508 KiB
22Accepted3/329ms4688 KiB