solution to sportsball
This commit is contained in:
parent
eeacab67d4
commit
e97f4e31b8
21
sportsball/sportsball.py
Normal file
21
sportsball/sportsball.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import itertools
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def run(nums):
|
||||||
|
best = 0
|
||||||
|
for i in xrange(len(nums)):
|
||||||
|
if nums[i] % 2 == 1:
|
||||||
|
cur_best = nums[i]
|
||||||
|
if cur_best > best: best = cur_best
|
||||||
|
for j in xrange(i + 1, len(nums)):
|
||||||
|
if nums[j] % 2 == 0:
|
||||||
|
break
|
||||||
|
cur_best += nums[j]
|
||||||
|
if cur_best > best:
|
||||||
|
best = cur_best
|
||||||
|
print best
|
||||||
|
|
||||||
|
for line in sys.stdin:
|
||||||
|
nums = [int(i) for i in line.strip().split()]
|
||||||
|
run(nums)
|
3
sportsball/stdin1.txt
Normal file
3
sportsball/stdin1.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
4 8 15 16 -23 42
|
||||||
|
41 4 -36 35 47 8 -21 8
|
||||||
|
1 43 -31 17 23 -45 -42 32 -2 -28
|
Loading…
Reference in New Issue
Block a user