fork download
  1. def getPoolSize(array):
  2. topVertex = None
  3. poolSize = 0
  4.  
  5. for i in xrange(1, len(array)-1):
  6. if not topVertex:
  7. topVertex = i
  8. continue
  9.  
  10. # The end of pool
  11. if array[i] >= array[topVertex]:
  12. topVertex = i
  13.  
  14. poolSize += array[topVertex] - array[i]
  15.  
  16. return poolSize
  17.  
  18.  
  19. if __name__ == "__main__":
  20. poolsArrays = ( [2, 5, 1, 2, 3, 4, 7, 7, 6],
  21. [2, 5, 1, 3, 1, 2, 1, 7, 7, 6],
  22. [2, 5, 1, 5, 1, 5],
  23. [1, 5, 4, 3, 2, 1],
  24. [0, 5, 0, 1, 0, 2, 0])
  25. for pool in poolsArrays:
  26. print ( getPoolSize(pool) )
  27.  
  28.  
Success #stdin #stdout 0.01s 7896KB
stdin
Standard input is empty
stdout
10
17
8
6
17