29252023-02-04 14:44:23horvathabelSíkság (55)cpp17Wrong answer 44/5535ms5348 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 (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
base44/55
1Accepted0/03ms2088 KiB
2Accepted0/04ms2380 KiB
3Accepted2/22ms2116 KiB
4Accepted2/22ms2112 KiB
5Wrong answer0/23ms2384 KiB
6Accepted2/23ms2452 KiB
7Accepted3/33ms2664 KiB
8Accepted2/23ms2912 KiB
9Accepted3/33ms3084 KiB
10Accepted3/36ms3520 KiB
11Accepted3/34ms3764 KiB
12Accepted3/34ms3772 KiB
13Accepted3/332ms4684 KiB
14Accepted3/319ms4772 KiB
15Accepted3/327ms5052 KiB
16Accepted3/334ms4988 KiB
17Wrong answer0/335ms5112 KiB
18Wrong answer0/335ms5196 KiB
19Accepted3/335ms5196 KiB
20Accepted3/335ms5176 KiB
21Accepted3/318ms4796 KiB
22Wrong answer0/328ms5348 KiB