fork(1) download
  1. def f(a):
  2. h=[]
  3. while a:x,w,*a=a;h[:x+w]=(h+[0]*x)[:x]+[max(h[x:x+w]+[0])+1]*w
  4. return h
  5.  
  6. inputs = [
  7. [2,4, 4,6, 12,1],
  8. [0,5, 9,1, 6,4, 2,5],
  9. [0,5, 9,1, 2,5, 6,4],
  10. [0,5, 2,5, 6,4, 9,1],
  11. [20,1, 20,1, 20,1],
  12. [5,5],
  13. [0,2, 1,2, 2,2, 3,2, 4,2, 5,2, 6,2, 7,2, 8,4],
  14. ]
  15.  
  16. for i in inputs:
  17. print(f(i))
Success #stdin #stdout 0.02s 9936KB
stdin
Standard input is empty
stdout
[0, 0, 1, 1, 2, 2, 2, 2, 2, 2, 0, 0, 1]
[1, 1, 3, 3, 3, 3, 3, 2, 2, 2]
[1, 1, 2, 2, 2, 2, 3, 3, 3, 3]
[1, 1, 2, 2, 2, 2, 3, 3, 3, 4]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3]
[0, 0, 0, 0, 0, 1, 1, 1, 1, 1]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9, 9]