-
Notifications
You must be signed in to change notification settings - Fork 0
/
bai4.py
54 lines (48 loc) · 1005 Bytes
/
bai4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
length = int(input())
array = [int(i) for i in input().split(' ')]
maximum = 0
i = 1
found = False
while i < length:
ascending = 0
while (i < length) and (array[i] > array[i - 1]):
ascending += 1
i += 1
if ascending > 0:
descending = 0
while (i < length) and (array[i] < array[i - 1]):
descending += 1
i += 1
if descending > 0:
maximum_local = min(ascending, descending)
maximum = max(maximum, maximum_local)
found = True
if ascending == 0:
i += 1
if found:
print(maximum, end=' ')
else:
print(0, end=' ')
minimum = 0
i = 1
found = False
while i < length:
descending = 0
while (i < length) and (array[i] < array[i - 1]):
descending += 1
i += 1
if descending > 0:
ascending = 0
while (i < length) and (array[i] > array[i - 1]):
ascending += 1
i += 1
if ascending > 0:
minimum_local = min(descending, ascending)
minimum = max(minimum, minimum_local)
found = True
if descending == 0:
i += 1
if found:
print(minimum)
else:
print(0)