fork download
  1. # -- read input --
  2. (x, X, y, Y) = map(int, raw_input().split())
  3. b = int(raw_input())
  4. N = int(raw_input())
  5. xhash = {}
  6. for _ in range(N):
  7. (x1, v) = map(int, raw_input().split())
  8. xhash[x1] = v
  9.  
  10. # -- calculate the histogram --
  11. keys = sorted(xhash.keys())
  12. for i in range(X/b):
  13. s = 0
  14. for j in range(b):
  15. s += xhash[keys[i*b+j]]
  16. for j in range(b):
  17. xhash[keys[i*b+j]] = s/b
  18.  
  19. # -- print chart --
  20. d_x, d_y = len(str(X)), len(str(Y))
  21. fmt = lambda x: '*'.rjust(d_x) if a <= xhash[x] else ' '.rjust(d_x)
  22. for a in range(Y, y-1, -1):
  23. print str(a).rjust(d_y), ' '.join(map(fmt, keys))
  24. print str('').rjust(d_y), ' '.join(map(lambda x: str(x).rjust(d_x), keys))
Success #stdin #stdout 0s 23352KB
stdin
1 4 1 10
2
4
1 3
2 3
3 2
4 6
stdout
10        
 9        
 8        
 7        
 6        
 5        
 4     * *
 3 * * * *
 2 * * * *
 1 * * * *
   1 2 3 4