fork download
  1. for _ in range(int(input())):
  2. n = int(input())
  3. d = {}
  4. m = 0
  5. for _ in range(n):
  6. x, y = map(int, input().split())
  7. d[x] = y
  8. if x > m:
  9. m = x
  10.  
  11. p = d.get(0, 0)
  12. ans = m
  13. x = 1
  14. while p > 0:
  15. ans = max(ans, x)
  16. cx = d.get(x, 0)
  17. if p > cx:
  18. p = (p + cx) // 2
  19. else:
  20. p = p
  21. x += 1
  22.  
  23. print(ans)
  24.  
Success #stdin #stdout 0.06s 14044KB
stdin
10
4
2 2
0 3
4 1
1 2
1
10 1
1
2 3
3
0 1
2 2
3 1
3
0 4
1 2
2 1
1
0 100
2
2 7
3 1
2
0 1
3 3
3
0 1
1 1
59 1
4
0 5
1 1
2 3
3 1
stdout
5
10
2
3
4
7
3
3
59
5