Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- t = int(input())
- for t_i in range(t):
- n, H, A = map(int, input().split())
- p = []
- for i in range(n):
- h, a = map(int, input().split())
- x = h // A
- if h % A != 0:
- x += 1
- p.append([h, a, x * a])
- p = sorted(p, key = lambda item: item[2], reverse = True)
- res = None
- for i in range(n):
- a1 = H // p[i][1]
- if H % p[i][1] != 0:
- a1 += 1
- a2 = p[i][0] // A
- if p[i][0] % A != 0:
- a2 += 1
- if a1 < a2:
- H = H - p[i][1] * a1
- p[i][0] = p[i][0] - A * a1
- else:
- H = H - p[i][1] * a2
- p[i][0] = p[i][0] - A * a2
- if H <= 0:
- res = i
- break
- if res == None:
- print (-1)
- else:
- print (res)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement