Problem p02883 (C++)

Buggy submission (status: Runtime Error):
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

/* INCLUDES */
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

/* TYPES */
#define long long long
#define all(v) v.begin(), v.end()
typedef pair<int, int> pii;
typedef pair<int64_t, int> pli;
typedef pair<int64_t, int64_t> pll;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpi;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<vector<int64_t>> vvl;

/* CONSTANTS */
const long MOD = 1e9 + 7, LINF = 1e18 + 1e16;
const int INF = 1e9 + 1;
const double EPS = 1e-10;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};

/* FUNCTIONS */
template <typename T, typename U> inline void setMin(T &x, U y) {
  if (y < x)
    x = y;
}
template <typename T, typename U> inline void setMax(T &x, U y) {
  if (x < y)
    x = y;
}
template <typename T> inline T gcd(T a, T b) {
  T c;
  while (b)
    c = b, b = a % b, a = c;
  return a;
}
template <typename T> inline T square(T a, T b) { return a * b; }

const int N = 1e5 + 1;

class TaskE {

  long n, k, a[N], f[N];

public:
  void solve(istream &cin, ostream &cout) {
    cin >> n >> k;
    for (int i = 0; i < n; i++)
      cin >> a[i];
    sort(a, a + n);
    for (int i = 0; i < n; i++)
      cin >> f[i];

    long l = 0, r = 1e12;
    while (l < r) {
      long mid = l + r >> 1;
      vector<long> b;
      for (int i = 0; i < n; i++) {
        b.push_back(mid / f[i]);
      }
      sort(b.begin(), b.end());
      long req = 0;
      for (int i = 0; i < n; i++) {
        req += max(a[i] - b[i], 0ll);
      }
      if (req > k)
        l = mid + 1;
      else
        r = mid;
    }

    cout << l << endl;
  }
};

class Solver {
public:
  void solve(std::istream &in, std::ostream &out) {
    TaskE *obj = new TaskE();
    obj->solve(in, out);
    delete obj;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  Solver solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}

Fixed submission:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

/* INCLUDES */
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

/* TYPES */
#define long long long
#define all(v) v.begin(), v.end()
typedef pair<int, int> pii;
typedef pair<int64_t, int> pli;
typedef pair<int64_t, int64_t> pll;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpi;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<vector<int64_t>> vvl;

/* CONSTANTS */
const long MOD = 1e9 + 7, LINF = 1e18 + 1e16;
const int INF = 1e9 + 1;
const double EPS = 1e-10;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};

/* FUNCTIONS */
template <typename T, typename U> inline void setMin(T &x, U y) {
  if (y < x)
    x = y;
}
template <typename T, typename U> inline void setMax(T &x, U y) {
  if (x < y)
    x = y;
}
template <typename T> inline T gcd(T a, T b) {
  T c;
  while (b)
    c = b, b = a % b, a = c;
  return a;
}
template <typename T> inline T square(T a, T b) { return a * b; }

const int N = 2e5 + 1;

class TaskE {

  long n, k, a[N], f[N];

public:
  void solve(istream &cin, ostream &cout) {
    cin >> n >> k;
    for (int i = 0; i < n; i++)
      cin >> a[i];
    sort(a, a + n);
    for (int i = 0; i < n; i++)
      cin >> f[i];

    long l = 0, r = 1e12;
    while (l < r) {
      long mid = l + r >> 1;
      vector<long> b;
      for (int i = 0; i < n; i++) {
        b.push_back(mid / f[i]);
      }
      sort(b.begin(), b.end());
      long req = 0;
      for (int i = 0; i < n; i++) {
        req += max(a[i] - b[i], 0ll);
      }
      if (req > k)
        l = mid + 1;
      else
        r = mid;
    }

    cout << l << endl;
  }
};

class Solver {
public:
  void solve(std::istream &in, std::ostream &out) {
    TaskE *obj = new TaskE();
    obj->solve(in, out);
    delete obj;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  Solver solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}