2022-2023/1NSI/Evaluations/DS_2023-03-31/annexes/sous_liste2.py

9 lines
265 B
Python

def pgsp2(lst:list):
sommes_max = [lst[0]]
for i in range(1, len(lst)):
if lst[i] > (sommes_max[-1] + lst[i]):
sommes_max.append(lst[i])
else:
sommes_max.append(sommes_max[-1] + lst[i])
return maximum(sommes_max)