fork(2) download
  1. def calculate(walls):
  2. prev = 0
  3. max = 0
  4. localSum = 0
  5. totalSum = 0
  6.  
  7. for i in xrange(len(walls)):
  8. if i < prev and max == 0:
  9. max = prev
  10.  
  11. if walls[i] >= max:
  12. max = 0
  13. totalSum += localSum
  14. localSum = 0
  15.  
  16. if not max == 0:
  17. localSum += max - walls[i]
  18.  
  19. prev = walls[i]
  20. return totalSum
  21.  
  22. print calculate([2, 5, 1, 2, 3, 4, 7, 7, 6])
Success #stdin #stdout 0.01s 7896KB
stdin
Standard input is empty
stdout
10