This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
def find_max_islands(lst):
i = 1 #this code is to remove adjacent same island heights
temp=-1
lst3=[]
for i in lst:
if i!=temp:
lst3+=[i]
temp=i
lst2 = []+lst
lst2.sort()#sort list in descending order to flood the islands
lst2.reverse()
lst3 = []+lst2
peakvalley = []
count = 0
islands=[]
for i in range(len(lst3)):
x = lst.index(lst3[i]) #identify where the island height is in original list
if x==len(lst)-1: #if i is the last element in the list
if lst[x]>lst[x-1]:
islands.append(1)
continue
if x == 0: #if i is the first element in the list
if lst[x]>lst[x+1]:
islands.append(1)
continue
if lst[x]>lst[x+1]and lst[x]>lst[x-1]: #if island is higher than those around it
islands.append(1)
if lst[x]<lst[x+1]and lst[x]<lst[x-1]: #if island is lower than those around it
islands.append(-1)
maxisle = 0
count = 0
d=0
for i in islands:
count+=i
d=max(count,d)
return d
from sys import stdin,stdout
n=int(stdin.readline())
lst=[]
for i in range(n):
lst+=[int(stdin.readline())]
stdout.write(str(find_max_islands(lst)))
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |