Problem p02883 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
// #define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X)                                                                 \
  {}
#define ARDEB(i, X)                                                            \
  {}
#define END                                                                    \
  {}
#endif
int ceil2(int a, int b) {
  if (a % b) {
    return a / b + 1;
  } else {
    return a / b;
  }
}
// typedef long long int ll;
typedef pair<int, int> P;
struct edge {
  int to, cost;
};

int n, k;
int a[111111], f[111111];

int ans;
signed main() {
  cin >> n >> k;
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> f[i];
  sort(a, a + n);
  sort(f, f + n, greater<>());
  int ng = -1, ok = 10000000000000;
  while (abs(ok - ng) > 1) {
    int mid = (ng + ok) / 2;
    int syugyo = 0;
    rep(i, n) {
      if (a[i] * f[i] > mid) {
        syugyo += ceil2(a[i] * f[i] - mid, f[i]);
      }
    }
    if (syugyo <= k)
      ok = mid;
    else
      ng = mid;
  }
  cout << ok << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
// #define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X)                                                                 \
  {}
#define ARDEB(i, X)                                                            \
  {}
#define END                                                                    \
  {}
#endif
int ceil2(int a, int b) {
  if (a % b) {
    return a / b + 1;
  } else {
    return a / b;
  }
}
// typedef long long int ll;
typedef pair<int, int> P;
struct edge {
  int to, cost;
};

int n, k;
int a[211111], f[211111];

int ans;
signed main() {
  cin >> n >> k;
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> f[i];
  sort(a, a + n);
  sort(f, f + n, greater<>());
  int ng = -1, ok = 10000000000000;
  while (abs(ok - ng) > 1) {
    int mid = (ng + ok) / 2;
    int syugyo = 0;
    rep(i, n) {
      if (a[i] * f[i] > mid) {
        syugyo += ceil2(a[i] * f[i] - mid, f[i]);
      }
    }
    if (syugyo <= k)
      ok = mid;
    else
      ng = mid;
  }
  cout << ok << endl;
}