Advertisement
j33vansh

Question 5 Rocky Bhai Solution

May 8th, 2022
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. def BinarySearch():
  2.     left = 0
  3.     right = 10**9+101
  4.     res = 0
  5.     while left <= right:
  6.         Sum = [0] * m
  7.         mid = (left+right) // 2
  8.         for i in range (m):
  9.             Sum[i] = max((mid - t[i])//p[i] + 1, 0)
  10.         Sum.sort(reverse = True)
  11.         x = sum(Sum[0:(n)])
  12.         if x >= k:
  13.             right = mid - 1
  14.             res = mid
  15.         else:
  16.             left = mid + 1
  17.    
  18.     return res
  19.  
  20. a = int(input())
  21. while a!= 0:
  22.     a -= 1
  23.     m,n,k = map(int, input().split())
  24.     t = list(map(int, input().split()))
  25.     p = list(map(int, input().split()))
  26.     print(BinarySearch())
  27.   # cook your dish here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement