-
Notifications
You must be signed in to change notification settings - Fork 14
/
10684 - The jackpot.py
47 lines (38 loc) · 1.13 KB
/
10684 - The jackpot.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
import sys
def kadane(array):
maxL, maxR, maxSum = -1,-1,0
currL, currR, currSum = 0,0,0
for i,a in enumerate(array):
if currSum < 0:
currL, currR, currSum = i,i+1, a
else:
currR , currSum = i+1, currSum + a
if maxSum < currSum or (maxSum == currSum and currR - currL > maxR - maxL):
maxL , maxR , maxSum = currL, currR, currSum
return maxSum
'''
def Solve(N,array):
#N,array = par
maxL, maxR, maxSum = kadane(array)
if maxSum > 0:
return 'The maximum winning streak is %d.'%(maxSum)
else:
return 'Losing streak.'
'''
if __name__ == '__main__':
while True:
#sys.stdin = open("jackpot.txt")
N = input()
if N == "":
N = input()
N = int(N)
if N == 0:
break
array = []
while len(array) < N:
array.extend(map(int, input().split()))
maxSum = kadane(array)
if maxSum > 0:
print("The maximum winning streak is %d."%(maxSum))
else:
print("Losing streak.")