prithivMLmods/Coder-Stat huggingface dataset:
Problem p02883 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  int n, k;
  cin >> n >> k;

  vector<long long> a(n), d(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];

  for (int i = 0; i < n; ++i)
    cin >> d[i];

  sort(a.begin(), a.end());
  sort(d.begin(), d.end(), greater<long long>());

  auto check = [&](long long x) {
    long long ret = 0;
    for (int i = 0; i < n; ++i) {
      long long cur = x / d[i];
      ret += max(0ll, a[i] - cur);
    }
    return ret;
  };

  long long l = 0, r = 1e18;
  while (l < r) {
    long long mid = (l + r) / 2;
    if (check(mid) <= k)
      r = mid;
    else
      l = mid + 1;
  }

  cout << r << '\n';
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  long long n, k;
  cin >> n >> k;

  vector<long long> a(n), d(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];

  for (int i = 0; i < n; ++i)
    cin >> d[i];

  sort(a.begin(), a.end());
  sort(d.begin(), d.end(), greater<long long>());

  auto check = [&](long long x) {
    long long ret = 0;
    for (int i = 0; i < n; ++i) {
      long long cur = x / d[i];
      ret += max(0ll, a[i] - cur);
    }
    return ret;
  };

  long long l = 0, r = 1e18;
  while (l < r) {
    long long mid = (l + r) / 2;
    if (check(mid) <= k)
      r = mid;
    else
      l = mid + 1;
  }

  cout << r << '\n';
}
Problem p02883 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef int64_t Int;

Int N, K;
vector<Int> A(200010), F(100010);

bool possible(Int X) {
  Int shugyo = 0;
  for (int i = 0; i < N; i++) {
    shugyo += max((Int)0, (A[i] - X / F[i]));
  }

  return (shugyo <= K);
}

int main() {
  cin >> N >> K;

  Int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
  }
  for (int i = 0; i < N; i++)
    cin >> F[i];

  if (sum <= K) {
    cout << 0 << endl;
    return 0;
  }

  sort(A.begin(), A.begin() + N);
  sort(F.begin(), F.begin() + N, greater<Int>());

  Int ng = -1, ok = 1e13;
  while (ok - ng > 1) {
    Int m = (ok + ng) / 2;

    if (possible(m))
      ok = m;
    else
      ng = m;
  }

  cout << ok << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef int64_t Int;

Int N, K;
vector<Int> A(200010, 0), F(200010, 0);

bool possible(Int X) {
  Int shugyo = 0;
  for (int i = 0; i < N; i++) {
    shugyo += max((Int)0, (A[i] - X / F[i]));
  }

  return (shugyo <= K);
}

int main() {
  cin >> N >> K;

  Int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
  }
  for (int i = 0; i < N; i++)
    cin >> F[i];

  if (sum <= K) {
    cout << 0 << endl;
    return 0;
  }

  sort(A.begin(), A.begin() + N);
  sort(F.begin(), F.begin() + N, greater<Int>());

  Int ng = -1, ok = 1e13;
  while (ok - ng > 1) {
    Int m = (ok + ng) / 2;

    if (possible(m))
      ok = m;
    else
      ng = m;
  }

  cout << ok << endl;
}
Problem p02883 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (n); ++i)
#define InitRep(i, begin, n) for (int i = (begin); i < (n); ++i)
#define RepItr(it, begin, end) for (auto it = (begin); it != (end); ++it)
using int64 = long long;
using vint = vector<int>;
using vint64 = vector<int64>;
static double PI = ::acos(-1);

int main() {
  int n, k;
  cin >> n >> k;
  vint a(n), f(n);
  Rep(i, n) { cin >> a[i]; }
  Rep(i, n) { cin >> f[i]; }
  sort(a.begin(), a.end());
  sort(f.begin(), f.end(), greater<int>());

  int64 left = -1, right = 1e12;
  while (left + 1 < right) {
    int64 center = (left + right) / 2;
    int64 sum = 0;
    Rep(i, n) { sum += max(0LL, a[i] - center / f[i]); }
    if (k >= sum) {
      right = center;
    } else {
      left = center;
    }
  }
  cout << right << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (n); ++i)
#define InitRep(i, begin, n) for (int i = (begin); i < (n); ++i)
#define RepItr(it, begin, end) for (auto it = (begin); it != (end); ++it)
using int64 = long long;
using vint = vector<int>;
using vint64 = vector<int64>;
static double PI = ::acos(-1);

int main() {
  int64 n, k;
  cin >> n >> k;
  vint a(n), f(n);
  Rep(i, n) { cin >> a[i]; }
  Rep(i, n) { cin >> f[i]; }
  sort(a.begin(), a.end());
  sort(f.begin(), f.end(), greater<int>());

  int64 left = -1, right = 1e12;
  while (left + 1 < right) {
    int64 center = (left + right) / 2;
    int64 sum = 0;
    Rep(i, n) { sum += max(0LL, a[i] - center / f[i]); }
    if (k >= sum) {
      right = center;
    } else {
      left = center;
    }
  }
  cout << right << endl;

  return 0;
}
Problem p02883 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

int n;
int64_t k;
vector<int64_t> A;
vector<int64_t> F;
vector<int64_t> M;

bool check(int64_t ma) {
  int64_t remain = k;
  for (int i = 0; i < n; i++) {
    if (M[i] <= ma)
      continue;
    remain -= A[i] - ma / F[i];
  }

  return remain >= 0;
}

int main() {
  cin >> n;
  cin >> k;
  A.resize(n);
  F.resize(n);
  copy_n(istream_iterator<int64_t>(cin), n, A.begin());
  copy_n(istream_iterator<int64_t>(cin), n, F.begin());

  sort(A.begin(), A.end());
  sort(F.begin(), F.end(), greater<int64_t>());
  M.resize(n);

  for (int i = 0; i < n; i++)
    M[i] = A[i] * F[i];

  int64_t ng = -1, ok = 1e12 + 1;
  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    if (check(mid))
      ok = mid;
    else
      ng = mid;
  }

  cout << ok << endl;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int n;
int64_t k;
vector<int64_t> A;
vector<int64_t> F;
vector<int64_t> M;

bool check(int64_t ma) {
  int64_t remain = k;
  for (int i = 0; i < n; i++) {
    if (M[i] <= ma)
      continue;
    remain -= A[i] - ma / F[i];
  }

  return remain >= 0;
}

int main() {
  cin >> n;
  cin >> k;
  A.resize(n);
  F.resize(n);
  copy_n(istream_iterator<int64_t>(cin), n, A.begin());
  copy_n(istream_iterator<int64_t>(cin), n, F.begin());

  sort(A.begin(), A.end());
  sort(F.begin(), F.end(), greater<int64_t>());
  M.resize(n);

  for (int i = 0; i < n; i++)
    M[i] = A[i] * F[i];

  int64_t ng = -1, ok = 1e12 + 1;
  while (abs(ok - ng) > 1) {
    int64_t mid = (ok + ng) / 2;
    if (check(mid))
      ok = mid;
    else
      ng = mid;
  }

  cout << ok << endl;
}
Problem p02883 (C++)

Buggy submission (status: Time Limit Exceeded):
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

ll n, k;
vector<int> a(1000001), f(1000001);

// 二分探索法
// index が条件を満たすかどうか
bool isOK(ll index) {
  ll c = 0;
  for (int i = 0; i < n; i++) {
    c += max(0ll, (a[i] - index / f[i]));
    if (c > k)
      return false;
  }
  return true;
}
// 汎用的な二分探索のテンプレ
ll binary_search(ll m) {
  ll left = -1; // 「index = 0」が条件を満たすこともあるので、初期値は -1
  ll right =
      m; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は
         // a.size()

  /* どんな二分探索でもここの書き方を変えずにできる！ */
  while (right - left > 1) {
    int mid = (left + right) / 2;

    if (isOK(mid))
      right = mid;
    else
      left = mid;
  }

  /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている
   */
  return right;
}

int main() {
  ll b, c, d, w, h, i, j, l, m, x, y, z;
  ll ans = 0;
  string s;
  cin >> n >> k;
  vector<int> aa(n), ff(n);
  for (i = 0; i < n; i++)
    cin >> aa[i];
  for (i = 0; i < n; i++)
    cin >> ff[i];

  sort(aa.begin(), aa.end());
  sort(ff.begin(), ff.end());
  reverse(aa.begin(), aa.end());
  for (i = 0; i < n; i++) {
    a[i] = aa[i];
    f[i] = ff[i];
  }

  ans = binary_search((ll)a[0] * f[n - 1] + 1);
  cout << ans << endl;
  return 0;
}


Fixed submission:
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

ll n, k;
vector<int> a(1000001), f(1000001);

// 二分探索法
// index が条件を満たすかどうか
bool isOK(ll index) {
  ll c = 0;
  for (int i = 0; i < n; i++) {
    c += max(0ll, (a[i] - index / f[i]));
    if (c > k)
      return false;
  }
  return true;
}
// 汎用的な二分探索のテンプレ
ll binary_search(ll m) {
  ll left = -1; // 「index = 0」が条件を満たすこともあるので、初期値は -1
  ll right =
      m; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は
         // a.size()

  /* どんな二分探索でもここの書き方を変えずにできる！ */
  while (right - left > 1) {
    ll mid = right + (left - right) / 2;

    if (isOK(mid))
      right = mid;
    else
      left = mid;
  }

  /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている
   */
  return right;
}

int main() {
  ll b, c, d, w, h, i, j, l, m, x, y, z;
  ll ans = 0;
  string s;
  cin >> n >> k;
  vector<int> aa(n), ff(n);
  for (i = 0; i < n; i++)
    cin >> aa[i];
  for (i = 0; i < n; i++)
    cin >> ff[i];

  sort(aa.begin(), aa.end());
  sort(ff.begin(), ff.end());
  reverse(aa.begin(), aa.end());
  for (i = 0; i < n; i++) {
    a[i] = aa[i];
    f[i] = ff[i];
  }

  ans = binary_search((ll)a[0] * f[n - 1] + 1);
  cout << ans << endl;
  return 0;
}
Problem p02883 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const ll MAX = 200000, INF = 1e13;
ll n, k;

ll A[MAX], B[MAX], F[MAX];

bool C(ll x) {
  ll cnt = 0;
  sort(A, A + n);
  sort(F, F + n, greater<>());
  for (int i = 0; i < n; i++) {
    B[i] = x / F[i];
  }
  for (int i = 0; i < n; i++) {
    if (B[i] < A[i])
      cnt += A[i] - B[i];
  }
  if (cnt > k)
    return false;
  else
    return true;
}

void solve() {
  ll lb = 0, ub = INF;
  for (int i = 0; i < 1000; i++) {
    ll mid = (lb + ub) / 2;
    if (C(mid))
      ub = mid;
    else
      lb = mid;
  }

  printf("%lld\n", ub);
}

int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> A[i];
  for (int i = 0; i < n; i++)
    cin >> F[i];

  solve();
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const ll MAX = 200000, INF = 1e13;
ll n, k;

ll A[MAX], B[MAX], F[MAX];

bool C(ll x) {
  ll cnt = 0;
  sort(A, A + n);
  sort(F, F + n, greater<>());
  for (int i = 0; i < n; i++) {
    B[i] = x / F[i];
  }
  for (int i = 0; i < n; i++) {
    if (B[i] < A[i])
      cnt += A[i] - B[i];
  }
  if (cnt > k)
    return false;
  else
    return true;
}

void solve() {
  ll lb = 0, ub = INF;
  for (int i = 0; i < 100; i++) {
    ll mid = (lb + ub) / 2;
    if (C(mid))
      ub = mid;
    else
      lb = mid;
  }

  printf("%lld\n", ub);
}

int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> A[i];
  for (int i = 0; i < n; i++)
    cin >> F[i];

  solve();
}
Problem p02883 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, K;
  cin >> n >> K;
  vector<ll> a(n), f(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    cin >> f[i];
  sort(a.begin(), a.end());
  sort(f.rbegin(), f.rend());

  ll ok = 1e12, ng = -1;
  while (ok - ng > 1) {
    ll mid = (ok + ng) / 2;
    ll cnt = 0;
    for (int i = 0; i < n; i++) {
      cnt += max(a[i] - min(a[i], mid / f[i]), 0LL);
    }
    (cnt <= K ? ok : ng) = mid;
  }
  cout << ok << "\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  ll K;
  cin >> n >> K;
  vector<ll> a(n), f(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    cin >> f[i];
  sort(a.begin(), a.end());
  sort(f.rbegin(), f.rend());

  ll ok = 1e12, ng = -1;
  while (ok - ng > 1) {
    ll mid = (ok + ng) / 2;
    ll cnt = 0;
    for (int i = 0; i < n; i++) {
      cnt += max(a[i] - min(a[i], mid / f[i]), 0LL);
    }
    (cnt <= K ? ok : ng) = mid;
  }
  cout << ok << "\n";
  return 0;
}
Problem p02883 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  // freopen("sample3.in", "r", stdin);
  int N, K;
  cin >> N >> K;

  vector<long> A(N), F(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  for (int i = 0; i < N; ++i) {
    cin >> F[i];
  }
  sort(A.begin(), A.end());
  sort(F.begin(), F.end(), greater<long>());

  long left = 0L, right = 1e18L;
  while (left < right) {
    long mid = (left + right) >> 1, need = 0L;
    for (int i = 0; i < N; ++i)
      need += max(A[i] - mid / F[i], 0L);
    if (need > K)
      left = mid + 1;
    else
      right = mid;
  }
  cout << left << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  long N, K;
  cin >> N >> K;

  vector<long> A(N), F(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  for (int i = 0; i < N; ++i) {
    cin >> F[i];
  }
  sort(A.begin(), A.end());
  sort(F.begin(), F.end(), greater<long>());

  long left = 0L, right = 1e18L;
  while (left < right) {
    long mid = (left + right) >> 1, need = 0L;
    for (int i = 0; i < N; ++i)
      need += max(A[i] - mid / F[i], 0L);
    if (need > K)
      left = mid + 1;
    else
      right = mid;
  }
  cout << left << endl;
}
Problem p02883 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define il inline
#define rg register
#define gi read<int>
using namespace std;
const int O = 2e5 + 10, N = 1e6 + 10;
typedef long long ll;
template <class TT> il TT read() {
  TT o = 0, fl = 1;
  char ch = getchar();
  while (!isdigit(ch) && ch != '-')
    ch = getchar();
  if (ch == '-')
    fl = -1, ch = getchar();
  while (isdigit(ch))
    o = o * 10 + ch - '0', ch = getchar();
  return fl * o;
}
ll k, kk, l = 1, r, a[O], f[O], b[O], cnt[N], ans;
int n;
il bool check(ll x) {
  ll res = 0;
  memset(cnt, 0, sizeof cnt);
  for (int i = 1; i <= n; ++i)
    b[i] = x / f[i], ++cnt[b[i]];
  for (int i = 0, j = 0; i < N; ++i)
    while (cnt[i])
      b[j] = i, --cnt[i];
  for (int i = 1; i <= n; ++i)
    res += max(0ll, a[i] - b[i]);
  return res <= k;
}
int main() {
  n = gi(), k = read<ll>();
  for (int i = 1; i <= n; ++i)
    a[i] = read<ll>(), kk += a[i];
  for (int i = 1; i <= n; ++i)
    f[i] = read<ll>();
  if (kk <= k)
    return puts("0") & 0;
  sort(f + 1, f + n + 1);
  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);
  for (int i = 1; i <= n; ++i)
    r = max(r, a[i] * f[i]);
  while (l <= r) {
    ll mid = l + r >> 1;
    if (check(mid))
      r = mid - 1, ans = mid;
    else
      l = mid + 1;
  }
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define il inline
#define rg register
#define gi read<int>
using namespace std;
const int O = 2e5 + 10, N = 1e6 + 10;
typedef long long ll;
template <class TT> il TT read() {
  TT o = 0, fl = 1;
  char ch = getchar();
  while (!isdigit(ch) && ch != '-')
    ch = getchar();
  if (ch == '-')
    fl = -1, ch = getchar();
  while (isdigit(ch))
    o = o * 10 + ch - '0', ch = getchar();
  return fl * o;
}
ll k, kk, l = 1, r, a[O], f[O], b[O], cnt[N], ans;
int n;
il bool check(ll x) {
  ll res = 0;
  memset(cnt, 0, sizeof cnt);
  for (int i = 1; i <= n; ++i)
    b[i] = x / f[i], ++cnt[b[i] >= N ? (N - 1) : b[i]];
  for (int i = 0, j = 0; i < N; ++i)
    while (cnt[i])
      b[j] = i, --cnt[i];
  for (int i = 1; i <= n; ++i)
    res += max(0ll, a[i] - b[i]);
  return res <= k;
}
int main() {
  n = gi(), k = read<ll>();
  for (int i = 1; i <= n; ++i)
    a[i] = read<ll>(), kk += a[i];
  for (int i = 1; i <= n; ++i)
    f[i] = read<ll>();
  if (kk <= k)
    return puts("0") & 0;
  sort(f + 1, f + n + 1);
  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);
  for (int i = 1; i <= n; ++i)
    r = max(r, a[i] * f[i]);
  while (l <= r) {
    ll mid = l + r >> 1;
    if (check(mid))
      r = mid - 1, ans = mid;
    else
      l = mid + 1;
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p02883 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x)                                                                \
  {                                                                            \
    for (auto i : x) {                                                         \
      cout << i << " ";                                                        \
    }                                                                          \
    cout << endl;                                                              \
  }
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF = 1e12;
vector<ll> A;
vector<ll> F;
int N, K;

bool check(ll x) {
  // K回以下の修行でx以下の成績に出来るならtrueを返す
  ll cnt = 0;
  rep(i, N) {
    ll need = x / F[i];
    ll y = A[i] - need;
    cnt += ((y < 0) ? 0 : y);
  }
  return (cnt <= K);
}

int main() {
  // sort、二分探索
  cin >> N >> K;
  A.resize(N);
  F.resize(N);
  rep(i, N) cin >> A[i];
  rep(i, N) cin >> F[i];
  sort(A.begin(), A.end());
  sort(F.rbegin(), F.rend());

  ll ok = INF;
  ll ng = -1;
  while (abs(ng - ok) > 1) {
    ll mid = (ok + ng) / 2;
    if (check(mid))
      ok = mid;
    else
      ng = mid;
  }
  cout << ok << '\n';
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x)                                                                \
  {                                                                            \
    for (auto i : x) {                                                         \
      cout << i << " ";                                                        \
    }                                                                          \
    cout << endl;                                                              \
  }
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF = 1e12;
vector<ll> A;
vector<ll> F;
ll N, K;

bool check(ll x) {
  // K回以下の修行でx以下の成績に出来るならtrueを返す
  ll cnt = 0;
  rep(i, N) {
    ll need = x / F[i];
    ll y = A[i] - need;
    cnt += ((y < 0) ? 0 : y);
  }
  return (cnt <= K);
}

int main() {
  // sort、二分探索
  cin >> N >> K;
  A.resize(N);
  F.resize(N);
  rep(i, N) cin >> A[i];
  rep(i, N) cin >> F[i];
  sort(A.begin(), A.end());
  sort(F.rbegin(), F.rend());

  ll ok = INF;
  ll ng = -1;
  while (abs(ng - ok) > 1) {
    ll mid = (ok + ng) / 2;
    if (check(mid))
      ok = mid;
    else
      ng = mid;
  }
  cout << ok << '\n';
  return 0;
}
Problem p02883 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
#define ll long long
#define _for(i, a, b) for (int i = (a); i < (b); i++)
#define _rep(i, a, b) for (int i = (a); i <= (b); i++)
const int N = 1e5 + 100;
int a[N], f[N], n;
int main() {
  ll k;
  cin >> n >> k;
  _for(i, 0, n) cin >> a[i];
  _for(i, 0, n) cin >> f[i];
  sort(a, a + n);
  sort(f, f + n, greater<int>());
  ll l = 0, r = 1e12;
  while (l < r) {
    ll sum = 0;
    ll x = (l + r) >> 1;
    _for(i, 0, n) sum += max(0ll, a[i] - x / f[i]);
    if (sum <= k)
      r = x;
    else
      l = x + 1;
  }
  cout << l << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
#define ll long long
#define _for(i, a, b) for (int i = (a); i < (b); i++)
#define _rep(i, a, b) for (int i = (a); i <= (b); i++)
const int N = 2e5 + 100;
int a[N], f[N], n;
int main() {
  ll k;
  cin >> n >> k;
  _for(i, 0, n) cin >> a[i];
  _for(i, 0, n) cin >> f[i];
  sort(a, a + n);
  sort(f, f + n, greater<int>());
  ll l = 0, r = 1e12;
  while (l < r) {
    ll sum = 0;
    ll x = (l + r) >> 1;
    _for(i, 0, n) sum += max(0ll, a[i] - x / f[i]);
    if (sum <= k)
      r = x;
    else
      l = x + 1;
  }
  cout << l << endl;
  return 0;
}
Problem p02883 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define inf 2147483647
#define mem0(a) memset(a, 0, sizeof(a))
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rr read()
#define ll long long
#define pn putchar('\n')
#define ps putchar(' ')
#define repb(i, a, b) for (int i = a; i <= b; i++)
#define CloseIo ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
const int N = 1e5 + 5;

ll a[N], f[N];
ll n, m;
bool check(ll z, ll k) {
  rep(i, 0, n) {
    if (a[i] * f[n - 1 - i] < z)
      continue;
    if (a[i] - z / f[n - 1 - i] > k)
      return false;
    k -= (a[i] - z / f[n - 1 - i]);
  }
  return true;
}
int main() {

  scanf("%lld %lld", &n, &m);
  rep(i, 0, n) scanf("%lld", &a[i]);
  rep(i, 0, n) scanf("%lld", &f[i]);
  sort(a, a + n);
  sort(f, f + n);
  ll l = 0, r = 1e12 + 12;
  ll ans;
  while (l <= r) {
    ll mid = (l + r) >> 1;
    if (check(mid, m)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << ans;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define inf 2147483647
#define mem0(a) memset(a, 0, sizeof(a))
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rr read()
#define ll long long
#define pn putchar('\n')
#define ps putchar(' ')
#define repb(i, a, b) for (int i = a; i <= b; i++)
#define CloseIo ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
const int N = 1e6 + 5;

ll a[N], f[N];
ll n, m;
bool check(ll z, ll k) {
  rep(i, 0, n) {
    if (a[i] * f[n - 1 - i] < z)
      continue;
    if (a[i] - z / f[n - 1 - i] > k)
      return false;
    k -= (a[i] - z / f[n - 1 - i]);
  }
  return true;
}
int main() {

  scanf("%lld %lld", &n, &m);
  rep(i, 0, n) scanf("%lld", &a[i]);
  rep(i, 0, n) scanf("%lld", &f[i]);
  sort(a, a + n);
  sort(f, f + n);
  ll l = 0, r = 1e12 + 12;
  ll ans;
  while (l <= r) {
    ll mid = (l + r) >> 1;
    if (check(mid, m)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << ans;
}
Problem p02883 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

typedef vector<int> veci;
typedef pair<int, int> pii;
typedef vector<pii> vecii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vecl;
typedef vector<pll> vecll;
#define EPS (1e-9)
#define MOD (1e9 + 7)
#define fi first
#define se second
#define endl '\n'

void solve() {
  int n, k;
  cin >> n >> k;

  vector<ll> va(n);
  for (int i = 0; i < n; ++i)
    cin >> va[i];
  sort(va.rbegin(), va.rend());

  vector<ll> vf(n);
  for (int i = 0; i < n; ++i)
    cin >> vf[i];
  sort(vf.begin(), vf.end());

  ll l = 0, r = ll(1e12);
  while (l < r) {
    ll mid = l + (r - l) / 2;

    bool ok = true;
    ll rem = k;
    for (int i = 0; i < n; ++i) {
      ll needed = mid / vf[i];
      if (va[i] > needed) {
        rem -= va[i] - needed;
      }

      if (rem < 0) {
        ok = false;
        break;
      }
    }

    if (ok) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }
  cout << l << endl;
}

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
#ifdef LOCAL_TEST
  (void)argc;
  const string strpath = string(argv[0]) + string("-test.in");
  freopen(strpath.c_str(), "r", stdin);
  int tcs;
  cin >> tcs;
  while (tcs-- > 0)
#endif
    solve();
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

typedef vector<int> veci;
typedef pair<int, int> pii;
typedef vector<pii> vecii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vecl;
typedef vector<pll> vecll;
#define EPS (1e-9)
#define MOD (1e9 + 7)
#define fi first
#define se second
#define endl '\n'

void solve() {
  ll n, k;
  cin >> n >> k;

  vector<ll> va(n);
  for (int i = 0; i < n; ++i)
    cin >> va[i];
  sort(va.rbegin(), va.rend());

  vector<ll> vf(n);
  for (int i = 0; i < n; ++i)
    cin >> vf[i];
  sort(vf.begin(), vf.end());

  ll l = 0, r = ll(1e12);
  while (l < r) {
    ll mid = l + (r - l) / 2;

    bool ok = true;
    ll rem = k;
    for (int i = 0; i < n; ++i) {
      ll needed = mid / vf[i];
      if (va[i] > needed) {
        rem -= va[i] - needed;
      }

      if (rem < 0) {
        ok = false;
        break;
      }
    }

    if (ok) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }
  cout << l << endl;
}

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
#ifdef LOCAL_TEST
  (void)argc;
  const string strpath = string(argv[0]) + string("-test.in");
  freopen(strpath.c_str(), "r", stdin);
  int tcs;
  cin >> tcs;
  while (tcs-- > 0)
#endif
    solve();
}
Problem p02883 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n;
ll k, l, r, ans;
ll a[200010], f[200010];
bool cmp(int x, int y) { return x > y; }
bool check(ll x) {
  ll kk = k;
  for (int i = 1; i <= n; i++) {
    ll res = 0;
    while (res * f[i] <= x) {
      res++;
    }
    res--;
    kk -= a[i] - res;
  }
  return kk >= 0;
}
int main() {
  scanf("%d%lld", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++)
    scanf("%d", &f[i]);
  sort(a + 1, a + n + 1), sort(f + 1, f + n + 1, cmp);
  for (int i = 1; i <= n; i++) {
    r = max(r, a[i] * f[i]);
  }
  l = 0;
  while (l <= r) {
    ll mid = l + r >> 1;
    if (check(mid)) {
      ans = mid, r = mid - 1;
    } else
      l = mid + 1;
  }
  printf("%lld", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n;
ll k, l, r, ans;
ll a[200010], f[200010];
bool cmp(int x, int y) { return x > y; }
bool check(ll x) {
  ll kk = k;
  for (int i = 1; i <= n; i++) {
    ll res = x / f[i];
    if (a[i] >= res)
      kk -= a[i] - res;
  }
  return kk >= 0;
}
int main() {
  scanf("%d%lld", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++)
    scanf("%d", &f[i]);
  sort(a + 1, a + n + 1), sort(f + 1, f + n + 1, cmp);
  for (int i = 1; i <= n; i++) {
    r = max(r, a[i] * f[i]);
  }
  l = 0;
  while (l <= r) {
    ll mid = l + r >> 1;
    if (check(mid)) {
      ans = mid, r = mid - 1;
    } else
      l = mid + 1;
  }
  printf("%lld", ans);
  return 0;
}
Problem p02883 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  vector<int> F(N);
  for (int i = 0; i < N; i++) {
    cin >> F.at(i);
  }

  sort(A.begin(), A.end());
  sort(F.rbegin(), F.rend());
  int64_t l = -1, r = 1e12;
  while (l + 1 < r) {
    int64_t m = (l + r) / 2;
    int64_t k = 0;
    for (int i = 0; i < N; i++) {
      k += max((int64_t)0, A.at(i) - m / F.at(i));
    }
    if (k <= K) {
      r = m;
    } else {
      l = m;
    }
  }
  cout << r << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  int64_t K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  vector<int> F(N);
  for (int i = 0; i < N; i++) {
    cin >> F.at(i);
  }

  sort(A.begin(), A.end());
  sort(F.rbegin(), F.rend());
  int64_t l = -1, r = 1e12;
  while (l + 1 < r) {
    int64_t m = (l + r) / 2;
    int64_t k = 0;
    for (int i = 0; i < N; i++) {
      k += max((int64_t)0, A.at(i) - m / F.at(i));
    }
    if (k <= K) {
      r = m;
    } else {
      l = m;
    }
  }
  cout << r << endl;
}
Problem p02883 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int, int> pint;
#define All(s) s.begin(), s.end()
#define rAll(s) s.rbegin(), s.rend()
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
// 問題文および制約はちゃんと確認しよう！
// サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
// とりあえずサンプルを読んでから解法を考えよう？
lint a[100100], f[100100];
int main() {
  int n;
  lint k;
  cin >> n >> k;
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> f[i];
  sort(a, a + n);
  reverse(a, a + n);
  sort(f, f + n);
  lint hi = 123456789012345678LL, lo = 0;
  while (hi > lo) {
    lint mi = (hi + lo) / 2;
    lint sum = 0;
    rep(i, n) { sum += max(0LL, a[i] - mi / f[i]); }
    if (sum <= k)
      hi = mi;
    else
      lo = mi + 1;
  }
  cout << hi << endl;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int, int> pint;
#define All(s) s.begin(), s.end()
#define rAll(s) s.rbegin(), s.rend()
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
// 問題文および制約はちゃんと確認しよう！
// サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
// とりあえずサンプルを読んでから解法を考えよう？
lint a[200100], f[200100];
int main() {
  int n;
  lint k;
  cin >> n >> k;
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> f[i];
  sort(a, a + n);
  reverse(a, a + n);
  sort(f, f + n);
  lint hi = 123456789012345678LL, lo = 0;
  while (hi > lo) {
    lint mi = (hi + lo) / 2;
    lint sum = 0;
    rep(i, n) { sum += max(0LL, a[i] - mi / f[i]); }
    if (sum <= k)
      hi = mi;
    else
      lo = mi + 1;
  }
  cout << hi << endl;
}
Problem p02883 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;

vector<ll> a, b;
ll n, k;
bool check(long long x) {
  long long cnt = 0;
  rep(i, n) {
    cnt += max(0ll, a[i] - x / b[i]);
    if (cnt > k)
      return false;
  }
  return true;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> k;
  a.resize(n);
  b.resize(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end(), greater<ll>());
  ll l = -1, r = 1e12 + 1;
  while (r - l > 1) {
    int mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid;
  }
  cout << r;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;

vector<ll> a, b;
ll n, k;
bool check(long long x) {
  long long cnt = 0;
  rep(i, n) {
    cnt += max(0ll, a[i] - x / b[i]);
    if (cnt > k)
      return false;
  }
  return true;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> k;
  a.resize(n);
  b.resize(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end(), greater<ll>());
  ll l = -1, r = 1e12 + 1;
  while (r - l > 1) {
    ll mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid;
  }
  cout << r;
  return 0;
}
Problem p02883 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<long long> a(n);
  vector<long long> f(n);

  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    cin >> f[i];

  sort(a.begin(), a.end());
  sort(f.rbegin(), f.rend());

  long long l = -1;
  long long r = 1e12;
  while (l + 1 < r) {
    long long g = (l + r) / 2;
    bool flag = true;

    long long count = 0;
    for (long long i = 0; i < n; i++) {
      count += max(0LL, (a[i] - g / f[i]));
      if (count > k) {
        flag = false;
        break;
      }
    }
    (flag ? r : l) = g;
  }

  cout << r << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n);
  vector<long long> f(n);

  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    cin >> f[i];

  sort(a.begin(), a.end());
  sort(f.rbegin(), f.rend());

  long long l = -1;
  long long r = 1e12;
  while (l + 1 < r) {
    long long g = (l + r) / 2;
    bool flag = true;

    long long count = 0;
    for (long long i = 0; i < n; i++) {
      count += max(0LL, (a[i] - g / f[i]));
      if (count > k) {
        flag = false;
        break;
      }
    }
    (flag ? r : l) = g;
  }

  cout << r << endl;
}
Problem p02883 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n), f(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> f[i];

  sort(a.begin(), a.end());
  sort(f.rbegin(), f.rend());

  ll l = -1, r = 1e12;
  while (l + 1 < r) {
    ll c = (l + r) / 2;
    bool ok = [&]() {
      ll s = 0;
      rep(i, n) { s += max(0ll, a[i] - c / f[i]); }
      return s <= k;
    }();
    if (ok)
      r = c;
    else
      l = c;
  }
  cout << r << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int main() {
  int n;
  ll k;
  cin >> n >> k;
  vector<int> a(n), f(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> f[i];

  sort(a.begin(), a.end());
  sort(f.rbegin(), f.rend());

  ll l = -1, r = 1e12;
  while (l + 1 < r) {
    ll c = (l + r) / 2;
    bool ok = [&]() {
      ll s = 0;
      rep(i, n) { s += max(0ll, a[i] - c / f[i]); }
      return s <= k;
    }();
    if (ok)
      r = c;
    else
      l = c;
  }
  cout << r << endl;
  return 0;
}
Problem p02883 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<lint> a(n), f(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> f[i];
  }
  sort(all(a), greater<lint>());
  sort(all(f));
  lint cand_top = 1e+12, cand_bot = 0, cand_mid;
  while (cand_top > cand_bot) {
    lint need = 0;
    cand_mid = (cand_top + cand_bot) / 2;
    for (int i = 0; i < n; i++) {
      // temp:必要なマンパワー
      lint temp = cand_mid / f[i];
      need += max(a[i] - temp, (lint)0);
    }
    if (need <= k) {
      cand_top = cand_mid;
    } else {
      cand_bot = cand_mid;
    }
    if (cand_top - cand_bot <= 1) {
      break;
    }
  }
  // cand_botが実現できるか
  lint need = 0;
  for (int i = 0; i < n; i++) {
    // temp:必要なマンパワー
    lint temp = cand_bot / f[i];
    need += max(a[i] - temp, (lint)0);
  }
  if (need <= k) {
    cout << cand_bot << endl;
  } else {
    cout << cand_top << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

int main() {
  lint n, k;
  cin >> n >> k;
  vector<lint> a(n), f(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> f[i];
  }
  sort(all(a), greater<lint>());
  sort(all(f));
  lint cand_top = 1e+12, cand_bot = 0, cand_mid;
  while (cand_top > cand_bot) {
    lint need = 0;
    cand_mid = (cand_top + cand_bot) / 2;
    for (int i = 0; i < n; i++) {
      // temp:必要なマンパワー
      lint temp = cand_mid / f[i];
      need += max(a[i] - temp, (lint)0);
    }
    if (need <= k) {
      cand_top = cand_mid;
    } else {
      cand_bot = cand_mid;
    }
    if (cand_top - cand_bot <= 1) {
      break;
    }
  }
  // cand_botが実現できるか
  lint need = 0;
  for (int i = 0; i < n; i++) {
    // temp:必要なマンパワー
    lint temp = cand_bot / f[i];
    need += max(a[i] - temp, (lint)0);
  }
  if (need <= k) {
    cout << cand_bot << endl;
  } else {
    cout << cand_top << endl;
  }
}
Problem p02883 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep(i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL
#include "../../Lib/cout_container.hpp"
#define debug(x) cerr << #x " => " << x << endl
#else
#define debug(x) 0
#endif
using lint = long long;
constexpr int INF = 1 << 30;
constexpr lint INFL = 1LL << 62;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace {
struct INIT {
  INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} INIT;
} // namespace

int main(void) {
  int n, k;
  cin >> n >> k;
  vector<int> a(n), f(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> f[i];
  sort(all(a));
  sort(all(f), greater<int>());
  lint ok = 1e13, ng = -1;
  while (ok - ng > 1) {
    lint mid = (ok + ng) / 2, x = 0;
    rep(i, n) x += max(0LL, a[i] - mid / f[i]);
    if (x <= k)
      ok = mid;
    else
      ng = mid;
  }
  cout << ok << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep(i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL
#include "../../Lib/cout_container.hpp"
#define debug(x) cerr << #x " => " << x << endl
#else
#define debug(x) 0
#endif
using lint = long long;
constexpr int INF = 1 << 30;
constexpr lint INFL = 1LL << 62;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace {
struct INIT {
  INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} INIT;
} // namespace

int main(void) {
  lint n, k;
  cin >> n >> k;
  vector<int> a(n), f(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> f[i];
  sort(all(a));
  sort(all(f), greater<int>());
  lint ok = 1e13, ng = -1;
  while (ok - ng > 1) {
    lint mid = (ok + ng) / 2, x = 0;
    rep(i, n) x += max(0LL, a[i] - mid / f[i]);
    if (x <= k)
      ok = mid;
    else
      ng = mid;
  }
  cout << ok << endl;
  return 0;
}
Problem p02883 (C++)

Buggy submission (status: Time Limit Exceeded):
//** aman**/
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<ll, ll>
#define vi vector<ll>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define dl double
#define hell 1000000007
#define endl '\n'
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define ios                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)
using namespace std;
ll chk(vector<ll> a, vector<ll> b, ll n, ll k, ll mid) {
  for (ll i = 0; i < n; i++) {
    while (a[i] * b[i] > mid && k > 0) {
      a[i]--;
      k--;
    }
    if (a[i] * b[i] > mid)
      return 0;
  }
  return 1;
}
int main() {
  ios;
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n), b(n);
  for (ll i = 0; i < n; i++)
    cin >> a[i];
  for (ll i = 0; i < n; i++)
    cin >> b[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  reverse(a.begin(), a.end());
  ll s = 0, e = 1e15, mid, ans;
  while (s <= e) {
    mid = (s + e) / 2;
    // cout<<mid<<endl;
    // cout<<(a,b,n,k,mid)<<endl;
    if (chk(a, b, n, k, mid)) {
      ans = mid;
      e = mid - 1;
    } else {
      s = mid + 1;
    }
  }
  // cout<<k<<endl;
  //	for(int i=0;i<n;i++)cout<<a[i]<<" ";cout<<endl;
  cout << ans << endl;
  return 0;
}

Fixed submission:
//** aman**/
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<ll, ll>
#define vi vector<ll>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define dl double
#define hell 1000000007
#define endl '\n'
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define ios                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)
using namespace std;
ll chk(vector<ll> a, vector<ll> b, ll n, ll k, ll mid) {
  for (ll i = 0; i < n; i++) {
    while (a[i] * b[i] > mid && k > 0) {
      int x = a[i] - mid / b[i];
      a[i] = mid / b[i];
      k = k - x;
      if (k < 0)
        return 0;
    }
    if (a[i] * b[i] > mid)
      return 0;
  }
  return 1;
}
int main() {
  ios;
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n), b(n);
  for (ll i = 0; i < n; i++)
    cin >> a[i];
  for (ll i = 0; i < n; i++)
    cin >> b[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  reverse(a.begin(), a.end());
  ll s = 0, e = 1e15, mid, ans;
  while (s <= e) {
    mid = (s + e) / 2;
    // cout<<mid<<endl;
    // cout<<(a,b,n,k,mid)<<endl;
    if (chk(a, b, n, k, mid)) {
      ans = mid;
      e = mid - 1;
    } else {
      s = mid + 1;
    }
  }
  // cout<<k<<endl;
  //	for(int i=0;i<n;i++)cout<<a[i]<<" ";cout<<endl;
  cout << ans << endl;
  return 0;
}
Problem p02883 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y);

int main() {
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> a(n);
  vector<ll> f(n);
  sort(a.begin(), a.end());
  sort(f.rbegin(), f.rend());
  ll l = -1, r = 1e12;
  while (l + 1 < r) {
    ll c = (l + r) / 2;
    ll s = 0;
    rep(i, n) { s += max(ll(0), a[i] - c / f[i]); }
    if (s <= k)
      r = c;
    else
      l = c;
  }
  cout << r << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y);

int main() {
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> a(n);
  vector<ll> f(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> f[i];
  sort(a.begin(), a.end());
  sort(f.rbegin(), f.rend());
  ll l = -1, r = 1e12;
  while (l + 1 < r) {
    ll c = (l + r) / 2;
    ll s = 0;
    rep(i, n) { s += max(ll(0), a[i] - c / f[i]); }
    if (s <= k)
      r = c;
    else
      l = c;
  }
  cout << r << endl;
  return 0;
}
Problem p02883 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

vector<ll> a, f;
ll n;

ll binarySearch_latest(bool (*callback)(ll, ll), ll userQuery = 0) {
  int ng = -1;
  ll ok = 10e12;
  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;
    if (callback(mid, userQuery)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  return ok;
}
bool judge1(ll arrValue, ll user) {

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ll sa = a[i] * f[i] - arrValue;
    if (sa <= 0)
      continue;
    ll tmp = sa / f[i];
    if (sa % f[i] != 0)
      tmp++;
    ans += tmp;
  }

  return ans <= user;
}

int main() {
  ll k;
  cin >> n >> k;
  rep(i, n) {
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
  }
  rep(i, n) {
    int tmp;
    cin >> tmp;
    f.push_back(tmp);
  }

  sort(a.begin(), a.end(), greater<ll>());
  sort(f.begin(), f.end());

  cout << binarySearch_latest(judge1, k) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

vector<ll> a, f;
ll n;

ll binarySearch_latest(bool (*callback)(ll, ll), ll userQuery = 0) {
  ll ng = -1;
  ll ok = 10e12;
  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;
    if (callback(mid, userQuery)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  return ok;
}
bool judge1(ll arrValue, ll user) {

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ll sa = a[i] * f[i] - arrValue;
    if (sa <= 0)
      continue;
    ll tmp = sa / f[i];
    if (sa % f[i] != 0)
      tmp++;
    ans += tmp;
  }

  return ans <= user;
}

int main() {
  ll k;
  cin >> n >> k;
  rep(i, n) {
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
  }
  rep(i, n) {
    int tmp;
    cin >> tmp;
    f.push_back(tmp);
  }

  sort(a.begin(), a.end(), greater<ll>());
  sort(f.begin(), f.end());

  cout << binarySearch_latest(judge1, k) << endl;
}
Problem p02883 (C++)

Buggy submission (status: Runtime Error):
// AUTHOR: *Akash Shrivastva*
// Birla Institute of Technology,Mesra,India
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define M 1000000007
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define pll vector<pair<ll, ll>>
#define F first
#define S second
#define PII pair<ll, ll>
ll a[200001], f[200001], n, k;
ll check(ll mid) {
  ll i, c = 0;
  for (i = 0; i < n; i++) {
    if (a[i] * f[i] > mid)
      c += a[i] - mid / f[i];
  }
  if (c <= k)
    return 1;
  else
    return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  cin >> n >> k;
  a[n];
  f[n];
  ll i;
  for (i = 0; i < n; i++)
    cin >> a[i];
  for (i = 0; i < n; i++)
    cin >> f[i];
  sort(a, a + n);
  sort(f, f + n);
  reverse(f, f + n);
  ll lb = 0, up = pow(10, 12), ans, mid, cnt;
  while (lb <= up) {
    mid = (lb + up) / 2;
    if (check(mid))
      ans = mid, up = mid - 1;
    else
      lb = mid + 1;
  }
  cout << ans << endl;
}

Fixed submission:
// AUTHOR: *Akash Shrivastva*
// Birla Institute of Technology,Mesra,India
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define M 1000000007
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define pll vector<pair<ll, ll>>
#define F first
#define S second
#define PII pair<ll, ll>
ll a[200001], f[200001], n, k;
ll check(ll mid) {
  ll i, c = 0;
  for (i = 0; i < n; i++) {
    if (a[i] * f[i] > mid)
      c += a[i] - mid / f[i];
  }
  if (c <= k)
    return 1;
  else
    return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n >> k;
  a[n];
  f[n];
  ll i;
  for (i = 0; i < n; i++)
    cin >> a[i];
  for (i = 0; i < n; i++)
    cin >> f[i];
  sort(a, a + n);
  sort(f, f + n);
  reverse(f, f + n);
  ll lb = 0, up = pow(10, 12), ans, mid, cnt;
  while (lb <= up) {
    mid = (lb + up) / 2;
    if (check(mid))
      ans = mid, up = mid - 1;
    else
      lb = mid + 1;
  }
  cout << ans << endl;
}