Buggy python submission (verdict: Runtime Error):
// g++ -std=c++14 submit.cpp
// #define INF 9223372036854775807

# include <bits/stdc++.h>
// # define INF 1e9 + 1
using namespace std;

int main(){
  long int N, K;
  cin >> N >> K;
  vector<long int> A, F;
  long int v;

  long int tot = 0;
  for(int i=0; i<N; i++){
    cin >> v;
    A.push_back(v);
    tot += v;
  }

  if(tot <= K){
    cout << 0 << endl;
    exit(0);
  }

  for(long int i=0; i<N; i++){
    cin >> v;
    F.push_back(v);
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  sort(F.begin(), F.end());

  long int l, r;
  l = 0;
  vector<long int> B;
  for(long int i=0; i<N; i++) {
    B.push_back(A[i] * F[i]);
    r = max(r, A[i]*F[i]);
  }

  long int ans = 1e12;

  while(l < r){
    long int m = (l+r) / 2;
    long int count = 0;
    for(long int i=0; i<N; i++){
      if(B[i] - m > 0){
        count += (B[i] - m) / F[i];
        if((B[i] - m) % F[i] != 0) count++;
      }
    }

    if(count <= K){
      ans = min(ans, m);
      if(r == m+1) break;
      r = m+1;
    } else {
      if(l == m-1) break;
      l = m-1;
    }
  }
  cout << ans << endl;

}

Fixed submission:
def main():
 
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    F = list(map(int, input().split()))
    A.sort(reverse = True)
    F.sort()
 
    if K >= sum(A): return 0
 
    B = [A[i] * F[i] for i in range(N)]
    l, r = 0, max(B)
    ans = float('inf')
    while l <= r:
        m = (l+r) // 2
        count = 0
        for i in range(N):
            if B[i] - m > 0:
                count += (B[i] - m) // F[i]
                if (B[i] - m) % F[i] != 0:
                    count += 1
        if count <= K:
            ans = min(ans, m)
            if r == m-1: break
            r = m-1
        else:
            if l == m+1: break
            l = m+1
        # print(l, r)
    return ans
 
if __name__ == '__main__':
    print(main())

Buggy python submission (verdict: Time Limit Exceeded):
def main():

    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    F = list(map(int, input().split()))
    A.sort(reverse = True)
    F.sort()

    if K >= sum(A): return 0

    B = [A[i] * F[i] for i in range(N)]
    l, r = 0, max(B)
    ans = float('inf')
    while l <= r:
        m = (l+r) // 2
        count = 0
        for i in range(N):
            if B[i] - m > 0:
                count += (B[i] - m) // F[i]
                if (B[i] - m) % F[i] != 0:
                    count += 1
        if count <= K:
            ans = min(ans, m)
            if r == m-1: break
            r = m-1
        else:
            if l == m+1: break
            l = m+1
        # print(l, r)
    return ans

if __name__ == '__main__':
    print(main())

Fixed submission:
def main():
 
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    F = list(map(int, input().split()))
    A.sort(reverse = True)
    F.sort()
 
    if K >= sum(A): return 0
 
    B = [A[i] * F[i] for i in range(N)]
    l, r = 0, max(B)
    ans = float('inf')
    while l <= r:
        m = (l+r) // 2
        count = 0
        for i in range(N):
            if B[i] - m > 0:
                count += (B[i] - m) // F[i]
                if (B[i] - m) % F[i] != 0:
                    count += 1
        if count <= K:
            ans = min(ans, m)
            if r == m-1: break
            r = m-1
        else:
            if l == m+1: break
            l = m+1
        # print(l, r)
    return ans
 
if __name__ == '__main__':
    print(main())

Buggy python submission (verdict: Time Limit Exceeded):
def main():

    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    F = list(map(int, input().split()))
    A.sort(reverse = True)
    F.sort()

    if K >= sum(A): return 0

    B = [[A[i] * F[i], A[i], F[i]] for i in range(N)]
    l, r = 0, max([A[i]*F[i] for i in range(N)])
    # ans = float('inf')
    while l < r:
        m = (l+r) // 2
        count = 0
        for i in range(N):
            if B[i][0] - m > 0:
                if (B[i][0] - m) % B[i][2] == 0:
                    count += (B[i][0] - m) // B[i][2]
                else:
                    count += (B[i][0] - m) // B[i][2] + 1
        if count <= K:
            if r == m: break
            r = m
        else:
            # ans = min(ans, m)
            if l == m: break
            l = m
        # print(l, r)
    return r



if __name__ == '__main__':
    print(main())

Fixed submission:
def main():
 
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    F = list(map(int, input().split()))
    A.sort(reverse = True)
    F.sort()
 
    if K >= sum(A): return 0
 
    B = [A[i] * F[i] for i in range(N)]
    l, r = 0, max(B)
    ans = float('inf')
    while l <= r:
        m = (l+r) // 2
        count = 0
        for i in range(N):
            if B[i] - m > 0:
                count += (B[i] - m) // F[i]
                if (B[i] - m) % F[i] != 0:
                    count += 1
        if count <= K:
            ans = min(ans, m)
            if r == m-1: break
            r = m-1
        else:
            if l == m+1: break
            l = m+1
        # print(l, r)
    return ans
 
if __name__ == '__main__':
    print(main())

Buggy python submission (verdict: Time Limit Exceeded):
def main():

    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    F = list(map(int, input().split()))
    A.sort(reverse = True)
    F.sort()

    if K >= sum(A): return 0

    B = [[A[i] * F[i], A[i], F[i]] for i in range(N)]
    l, r = 0, max(A) * max(F)
    # ans = float('inf')
    while l < r:
        m = (l+r) // 2
        count = 0
        for i in range(N):
            if B[i][0] - m > 0:
                if (B[i][0] - m) % B[i][2] == 0:
                    count += (B[i][0] - m) // B[i][2]
                else:
                    count += (B[i][0] - m) // B[i][2] + 1
        if count <= K:
            if r == m: break
            r = m
        else:
            # ans = min(ans, m)
            if l == m: break
            l = m
        # print(l, r)
    return r



if __name__ == '__main__':
    print(main())

Fixed submission:
def main():
 
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    F = list(map(int, input().split()))
    A.sort(reverse = True)
    F.sort()
 
    if K >= sum(A): return 0
 
    B = [A[i] * F[i] for i in range(N)]
    l, r = 0, max(B)
    ans = float('inf')
    while l <= r:
        m = (l+r) // 2
        count = 0
        for i in range(N):
            if B[i] - m > 0:
                count += (B[i] - m) // F[i]
                if (B[i] - m) % F[i] != 0:
                    count += 1
        if count <= K:
            ans = min(ans, m)
            if r == m-1: break
            r = m-1
        else:
            if l == m+1: break
            l = m+1
        # print(l, r)
    return ans
 
if __name__ == '__main__':
    print(main())