29432023-02-04 18:24:29horvathabelSíkság (55)cpp17Accepted 55/5535ms5064 KiB

#include <bits/stdc++.h>
using namespace std;

int main() {
	int n;
	cin>>n;
	bool vane[n];
	int x;
	cin>>x;
	int mx=x, mn=x;
	int ans=1;  
	int mego=-1;
	int lk=-1;
	int k=1;
	vector<int> szm; 
	szm.push_back(x);
	for (int i=1; i<n;i++){
		int y; 
		cin>>y; 
		szm.push_back(y);
		if (ans>mego){
			mego=ans; 
			lk=k;
			}
		if (mx==mn){
			if (y==mx ) ans++;

			else if (y==mx+1){
				ans++;
				mx=y;
			}
			else if (y==mn-1){
				ans++;
				mn=y;
				}
				else{
					
					mn=y; 
					mx=y; 
					k=i+1; 
					ans=1;
				}
		}
		else{
			if (mn==y or mx==y) ans++;
			else{
				if (ans>mego){
					mego=ans; 
					lk=k;
				}
				if (y==szm[i-1]-1){
					int j=i-2;
					ans=2;
					mn=y;
					mx=szm[j+1];
					while (szm[j]==y+1 && j>=0){
						ans++;
						j--;
					}
					k=j+2;
				} 
				else if(y==szm[i-1]+1){
					int j=i-2;
					mn=y-1;
					mx=y;
					ans=2;
					while (szm[j]==y-1 && j>=0){
						ans++;
						j--;
					}
					k=j+2;
				}
				else{
					k=i+1;
					mn=y;
					mx=y;
					ans=1;
				}
			}
		}
		
	
	}
	if (ans>mego){
		cout<<ans<<" "<<k;
		return 0; 
	}
	
	cout<<mego<<" "<<lk; 
}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/03ms1812 KiB
2Accepted0/04ms2284 KiB
3Accepted2/23ms2268 KiB
4Accepted2/22ms2424 KiB
5Accepted2/22ms2640 KiB
6Accepted2/22ms2720 KiB
7Accepted3/33ms2980 KiB
8Accepted2/23ms3064 KiB
9Accepted3/33ms2976 KiB
10Accepted3/34ms3136 KiB
11Accepted3/34ms3140 KiB
12Accepted3/34ms3408 KiB
13Accepted3/332ms4432 KiB
14Accepted3/319ms4556 KiB
15Accepted3/327ms4640 KiB
16Accepted3/335ms4864 KiB
17Accepted3/334ms4808 KiB
18Accepted3/335ms4808 KiB
19Accepted3/335ms5064 KiB
20Accepted3/334ms4956 KiB
21Accepted3/318ms4564 KiB
22Accepted3/328ms4972 KiB