fork download
  1. def min_turns(h, d):
  2. position = 0
  3. health = h
  4. turns = 0
  5. cons_moves = 0
  6.  
  7. while position < d:
  8. next_move_cost = cons_moves + 1
  9. if health > next_move_cost:
  10. position += 1
  11. health -= next_move_cost
  12. cons_moves += 1
  13. turns += 1
  14. else:
  15. health += 1
  16. cons_moves = 0
  17. turns += 1
  18.  
  19. print(turns)
  20. t = int(input())
  21. for _ in range(t):
  22. h,d = map(int,input().split())
  23. min_turns(h,d)
Success #stdin #stdout 0.13s 14076KB
stdin
5
3 2
1 1
5 3
2 4
10 7
stdout
3
2
4
7
10