Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_next_block(idx, A):
- chopped = A[idx+1:idx+7]
- agg = 0
- last_idx = -1
- for i, v in enumerate(chopped):
- if v > -1:
- agg += v
- last_idx = i
- if last_idx == -1:
- max_val = -10001
- for i, v in enumerate(chopped):
- if v > max_val:
- max_val = v
- last_idx = i
- agg = max_val
- return agg, last_idx + 1 + idx
- def solution(A):
- # the solution is starting with the first number take all positive numbers in the
- # next block of 6. If there is no positive number in the next block of 6, then take
- # the largest (least negative or zero) number in that next block.
- # Then move to the next block of six after the last number taken.
- idx = 0
- total = A[0]
- while True:
- agg, idx = get_next_block(idx, A)
- print('adding %d' % agg)
- total += agg
- if idx == -1:
- break
- if idx == len(A) - 1:
- break
- return total
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement