fork(1) download
  1. n,m,t=gets.split(" ").map{|e| e.to_i}
  2. a=gets.split(" ").map{|e| e.to_i}
  3. com=[]
  4. m.times{
  5. com<<gets.split(" ").map{|e| e.to_i}
  6. }
  7. com.sort!
  8. t.times{|i|
  9. (n-1).downto(1){|p1|
  10. if a[p1-1]>0 then
  11. a[p1-1]-=1
  12. a[p1]+=1
  13. end
  14. }
  15. while com.size>0
  16. if com.size>0 && com[0][0]-1==i then
  17. a[com[0][1]-1]+=com[0][2]
  18. com.shift
  19. else
  20. break
  21. end
  22. end
  23. }
  24. puts a
Success #stdin #stdout 0.01s 8016KB
stdin
5 5 5
3 1 1 2 1
2 1 1
2 2 2
3 4 1
4 3 2
5 1 2
stdout
2
2
3
3
6