Problem p02883 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;

const ll MOD = (ll)998244353;
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_)                                                               \
  for (auto a_ : x_)                                                           \
    cerr << a_ << " ";                                                         \
  cerr << endl;
#define dbg3(x_, sx_)                                                          \
  rep(i, sx_) cerr << x_[i] << " ";                                            \
  cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) { return (a + b - 1) / b; }

void finish() {
  cout << -1 << endl;
  exit(0);
}

//------------------------------------------------------
ll n, k;
ll a[100010], f[100010];

bool can(ll Max_score) {
  ll cnt = 0;

  rep(i, n) {
    if (a[i] * f[i] <= Max_score)
      continue;
    cnt += a[i] - (Max_score / f[i]);
  }

  return cnt <= k;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << setiosflags(ios::fixed);

  cin >> n >> k;
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> f[i];
  sort(a, a + n);
  sort(f, f + n);
  reverse(f, f + n);
  ll lo = -1, hi = (ll)(1e12);
  while (hi - lo > 1) {
    ll mi = (lo + hi) / 2;
    if (can(mi))
      hi = mi;
    else
      lo = mi;
  }

  cout << hi << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;

const ll MOD = (ll)998244353;
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_)                                                               \
  for (auto a_ : x_)                                                           \
    cerr << a_ << " ";                                                         \
  cerr << endl;
#define dbg3(x_, sx_)                                                          \
  rep(i, sx_) cerr << x_[i] << " ";                                            \
  cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) { return (a + b - 1) / b; }

void finish() {
  cout << -1 << endl;
  exit(0);
}

//------------------------------------------------------
ll n, k;
ll a[200010], f[200010];

bool can(ll Max_score) {
  ll cnt = 0;

  rep(i, n) {
    if (a[i] * f[i] <= Max_score)
      continue;
    cnt += a[i] - (Max_score / f[i]);
  }

  return cnt <= k;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << setiosflags(ios::fixed);

  cin >> n >> k;
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> f[i];
  sort(a, a + n);
  sort(f, f + n);
  reverse(f, f + n);
  ll lo = -1, hi = (ll)(1e12);
  while (hi - lo > 1) {
    ll mi = (lo + hi) / 2;
    if (can(mi))
      hi = mi;
    else
      lo = mi;
  }

  cout << hi << endl;
  return 0;
}