124042024-12-16 17:00:16birozsSíkság (55)python3Time limit exceeded 17/55300ms15408 KiB
N = int(input())
lista = list(map(int,input().split()))
felso = lista[0]
also = lista[0]
hossz = 1
kezdo = 0
maxhossz = 1
maxkezdo = 0
for i in range(1,N):
    if lista[i] > felso:
        felso = lista[i]
    elif lista[i] < also:
        also = lista[i]
    if abs(also-felso) <= 1:
        hossz += 1
    else:
        if hossz > maxhossz:
            maxhossz = hossz
            maxkezdo = kezdo     
        also = felso = lista[i]
        j = i
        while j > 0 and abs(also-felso)<=1:
            j -= 1
            if lista[j] < also:
                also = lista[j]
            elif lista[j] > felso:
                felso = lista[j]
        kezdo = j + 1
        hossz = i - j
print(maxhossz,maxkezdo+1)
SubtaskSumTestVerdictTimeMemory
base17/55
1Accepted0/016ms3312 KiB
2Time limit exceeded0/0289ms4152 KiB
3Wrong answer0/216ms3116 KiB
4Accepted2/216ms3128 KiB
5Accepted2/216ms3320 KiB
6Accepted2/216ms2992 KiB
7Accepted3/316ms3128 KiB
8Accepted2/289ms3248 KiB
9Accepted3/334ms3136 KiB
10Time limit exceeded0/3280ms4152 KiB
11Accepted3/361ms3640 KiB
12Wrong answer0/321ms3896 KiB
13Time limit exceeded0/3300ms15408 KiB
14Time limit exceeded0/3277ms5236 KiB
15Time limit exceeded0/3287ms11972 KiB
16Time limit exceeded0/3275ms15152 KiB
17Time limit exceeded0/3282ms15224 KiB
18Time limit exceeded0/3300ms15396 KiB
19Time limit exceeded0/3282ms15104 KiB
20Time limit exceeded0/3284ms15124 KiB
21Time limit exceeded0/3280ms9056 KiB
22Time limit exceeded0/3300ms12568 KiB