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

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main(void) {
  long long N;
  cin >> N;
  long long minum = N - 1;
  for (long long i = 2; i <= N; i++) {
    if (N % i == 0) {
      minum = min(minum, i + N / i - 2);
    }
  }
  cout << minum << endl;
}

Fixed submission:
#include <iostream>
using namespace std;
int main(void) {
  long long N;
  cin >> N;
  long long minum = N - 1;
  for (long long i = 2; i * i <= N; i++) {
    if (N % i == 0) {
      minum = min(minum, i + N / i - 2);
    }
  }
  cout << minum << endl;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  long n, max, sa;
  cin >> n;
  sa = n;
  for (long i = 1; i <= n; i++) {
    if (n % i == 0) {
      long aho = n / i;
      long sasa = abs(aho - i);
      if (sasa <= sa) {
        sa = sasa;
        max = i;
      }
    }
  }
  long k = n / max;
  cout << k + max - 2;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  long n, max, sa;
  cin >> n;
  sa = n;
  max = 1;
  long jougen = n;
  if (n > 1000000)
    jougen = 1000000;
  for (long i = 1; i <= jougen; i++) {
    if (n % i == 0) {
      long aho = n / i;
      long sasa = abs(aho - i);
      if (sasa <= sa) {
        sa = sasa;
        max = i;
      }
    }
  }
  long k = n / max;
  cout << k + max - 2;
  return 0;
}
Problem p02881 (C++)

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

using namespace std;

int main() {
  int64_t n;
  cin >> n;
  int64_t ans = n - 1;

  for (int i = 1; i * i <= n; i++) {
    if (n % i != 0)
      continue;
    ans = min(ans, i + n / i - 2);
  }
  cout << ans << endl;
}

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

using namespace std;

int main() {
  int64_t n;
  cin >> n;
  int64_t ans = n - 1;

  for (int64_t i = 1; i * i <= n; i++) {
    if (n % i != 0)
      continue;
    ans = min(ans, i + n / i - 2);
  }
  cout << ans << endl;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
#define inf 1e12 + 7
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  ll ans = inf;
  for (ll i = 1; i <= n / 2 + 1; i++) {
    ll j = n / i;
    if (n % i == 0) {
      ans = min(ans, i - 1 + j - 1);
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
#define inf 1e12 + 7
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  ll ans = inf;
  for (ll i = 1; i <= sqrt(n); i++) {
    ll j = n / i;
    if (n % i == 0) {
      ans = min(ans, i - 1 + j - 1);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02881 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <math.h>

using namespace std;

int main() {
  long long int n;
  cin >> n;

  long long int nn = (long long int)sqrt(n);
  int ojisan;

  for (long long int i = 1; i < nn; i++) {
    if (n % i == 0)
      ojisan = i;
  }

  long long int ojisan1 = n / ojisan;

  //	cout << ojisan << '\n';
  cout << ojisan + ojisan1 - 2;
}

Fixed submission:
#include <iostream>
#include <math.h>

using namespace std;

int main() {
  long long int n;
  cin >> n;

  long long int nn = (long long int)sqrt(n);
  int ojisan;

  for (long long int i = 1; i <= nn; i++) {
    if (n % i == 0)
      ojisan = i;
  }

  long long int ojisan1 = n / ojisan;

  //	cout << ojisan << '\n';
  cout << ojisan + ojisan1 - 2;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#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>;

int main() {
  ll n;
  cin >> n;
  ll ans = 1e18;
  for (int i = 1; i * i <= n; i++) {
    if (n % i != 0)
      continue;
    ll j = n / i;
    ans = (ans, i + j - 2);
  }
  cout << ans << 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>;

int main() {
  ll n;
  cin >> n;
  ll ans = 1e18;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i != 0)
      continue;
    ll j = n / i;
    ans = (ans, i + j - 2);
  }
  cout << ans << endl;
  return 0;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long LL;
template <typename F, typename S>
std::ostream &operator<<(ostream &os, const pair<F, S> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "[";
  for (const T &a : v) {
    os << a << ", ";
  }
  os << "]";
  return os;
}
template <typename K, typename V>
ostream &operator<<(ostream &os, const map<K, V> &m) {
  os << "{";
  for (const auto &p : m) {
    os << p.first << ":" << p.second << ", ";
  }
  os << "}";
  return os;
}

int main() {
  LL n;
  cin >> n;
  LL ans = n + 1;
  for (LL i = 1; i < n; ++i) {
    if (n % i != 0)
      continue;
    ans = min(ans, i + n / i - 2);
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long LL;
template <typename F, typename S>
std::ostream &operator<<(ostream &os, const pair<F, S> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "[";
  for (const T &a : v) {
    os << a << ", ";
  }
  os << "]";
  return os;
}
template <typename K, typename V>
ostream &operator<<(ostream &os, const map<K, V> &m) {
  os << "{";
  for (const auto &p : m) {
    os << p.first << ":" << p.second << ", ";
  }
  os << "}";
  return os;
}

int main() {
  LL n;
  cin >> n;
  LL ans = n + 1;
  for (LL i = 1; i * i <= n; ++i) {
    if (n % i != 0)
      continue;
    ans = min(ans, i + n / i - 2);
  }
  cout << ans << endl;
  return 0;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> pii;
int main() {
  ll n;
  cin >> n;
  ll res = n - 1;
  for (ll i = 1; i <= i * i; i++) {
    if (n % i == 0)
      res = min(res, i - 1 + n / i - 1);
  }
  cout << res << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> pii;
int main() {
  ll n;
  cin >> n;
  ll res = n - 1;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0)
      res = min(res, i - 1 + n / i - 1);
  }
  cout << res << endl;
  return 0;
}
Problem p02881 (C++)

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

int main() {
  long long N;
  cin >> N;
  long long res;

  for (int i = 1; i * i < N; i++) {
    if (N % i == 0) {
      res = N / i + i - 2;
    }
  }

  cout << res;
}

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

int main() {
  long long N;
  cin >> N;
  long long res;

  for (long long i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      res = N / i + i - 2;
    }
  }

  cout << res;
}
Problem p02881 (C++)

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

int main() {
  long long x;
  cin >> x;
  long long ans = 1LL << 60;
  for (int i = 1; i * i <= x; ++i) {
    if (x % i)
      continue;
    ans = min(ans, i + x / i - 2);
  }
  cout << ans << endl;
}


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

int main() {
  long long x;
  cin >> x;
  long long ans = 1LL << 60;
  for (long long i = 1; i * i <= x; ++i) {
    if (x % i)
      continue;
    ans = min(ans, i + x / i - 2);
  }
  cout << ans << endl;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

long long MOD = 1000000007;

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

  long long ans = MOD * MOD;
  for (int i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      ans = min(ans, i + N / i - 2);
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

long long MOD = 1000000007;

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

  long long ans = MOD * MOD;
  for (long long i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      ans = min(ans, i + N / i - 2);
    }
  }
  cout << ans << endl;
}
Problem p02881 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

using namespace std;

int main() {
  long long n, a = 0, b = 0;

  cin >> n;

  for (long long d = 2; d * d <= n; d++) {
    if (n % d == 0)
      a = d;
  }

  b = n / a;

  cout << a - 1 + b - 1;

  return 0;
}


Fixed submission:
#include <iostream>

using namespace std;

int main() {
  unsigned long long n, a = 1, b = 0;

  cin >> n;

  for (long long d = 2; d * d <= n; d++) {
    if (n % d == 0)
      a = d;
  }

  b = n / a;

  cout << a - 1 + b - 1;

  return 0;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
  ll n;
  cin >> n;
  int m = sqrt(n);
  for (int i = m; i >= 1; i++) {
    if (n % i == 0) {
      m = n / i;
      ll sum = (i - 1) + (m - 1);
      cout << sum << endl;
      return 0;
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
  ll n;
  cin >> n;
  ll m = sqrt(n);
  for (ll i = m; i >= 1; i--) {
    if (n % i == 0) {
      m = n / i;
      ll sum = (i - 1) + (m - 1);
      cout << sum << endl;
      return 0;
    }
  }
  return 0;
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repe(i, n) for (int i = 0; i <= n; ++i)
#define repr(i, n) for (int i = n - 1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)

using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using V = vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main() {
  ll n;
  cin >> n;
  ll res = 1000000000010;
  ll tmp = 0;
  for (ll i = 1; i < n; ++i) {
    if (n % i == 0) {
      tmp = (i - 1) + (n / i) - 1;
      res = min(tmp, res);
    }
  }
  cout << res << "\n";
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repe(i, n) for (int i = 0; i <= n; ++i)
#define repr(i, n) for (int i = n - 1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)

using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using V = vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main() {
  ll n;
  cin >> n;
  ll res = 1000000000010;
  ll tmp = 0;
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      tmp = (i - 1) + (n / i) - 1;
      res = min(tmp, res);
    }
  }
  cout << res << "\n";
}
Problem p02881 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstring>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>

typedef long long ll;

using namespace std;

int main() {
  ll N;
  ll tmp, out;
  out = 1000000000000;
  cin >> N;

  for (ll i = 2; i <= N / 2; i++) {
    if (N % i == 0) {
      tmp = N / i;
      if (out > (tmp + i - 2))
        out = tmp + i - 2;
    }
  }
  if (out == 1000000000000)
    out = N - 1;
  cout << out;

  return 0;
}

Fixed submission:
#include <cstring>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>

typedef long long ll;

using namespace std;

int main() {
  ll N;
  ll tmp, out;
  out = 1000000000000;
  cin >> N;

  for (ll i = 2; i * i <= N; i++) {
    if (N % i == 0) {
      tmp = N / i;
      if (out > (tmp + i - 2))
        out = tmp + i - 2;
    }
  }
  if (out == 1000000000000)
    out = N - 1;
  cout << out;

  return 0;
}
Problem p02881 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 1; i < (int)(n); i++)

using namespace std;
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  ll max = 0;
  rep(i, sqrt(n)) {
    if (n % i == 0)
      max = i;
  }
  cout << max - 1 + n / max - 1 << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 1; i < (int)(n); i++)

using namespace std;
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  ll max = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0)
      max = i;
  }
  cout << max - 1 + n / max - 1 << endl;
}
Problem p02882 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
const int mod = 1000000007, MAX = 100003, INF = 1 << 30;

int main() {

  double A, B, X;
  cin >> A >> B >> X;
  double S = X / A;

  if (A * A * B == X)
    return 1;

  double left = 0.0, right = M_PI / 2.0;

  for (int i = 0; i < 300; i++) {
    double mid = (left + right) / 2.0;
    double l = A * sin(mid), h = B * sin(M_PI / 2.0 - mid);
    double size;

    if (l <= h) {
      size = A * B - A * A * tan(mid) / 2.0;
    } else {
      size = B * B * tan(M_PI / 2.0 - mid) / 2.0;
    }

    if (size >= S)
      left = mid;
    else
      right = mid;
  }

  printf("%.12lf\n", left * 90.0 / (M_PI / 2.0));
  // cout<<setprecision(25)<<left*90.0/(M_PI/2.0)<<endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
const int mod = 1000000007, MAX = 100003, INF = 1 << 30;

int main() {

  double A, B, X;
  cin >> A >> B >> X;
  double S = X / A;

  if (A * A * B == X) {
    cout << 1.130863886742583809729988e-14 << endl;
    return 0;
  }

  double left = 0.0, right = M_PI / 2.0;

  for (int i = 0; i < 300; i++) {
    double mid = (left + right) / 2.0;
    double l = A * sin(mid), h = B * sin(M_PI / 2.0 - mid);
    double size;

    if (l <= h) {
      size = A * B - A * A * tan(mid) / 2.0;
    } else {
      size = B * B * tan(M_PI / 2.0 - mid) / 2.0;
    }

    if (size >= S)
      left = mid;
    else
      right = mid;
  }

  printf("%.12lf\n", left * 90.0 / (M_PI / 2.0));
  // cout<<setprecision(25)<<left*90.0/(M_PI/2.0)<<endl;
}
Problem p02882 (C++)

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  double base, height, waterVolume;
  cin >> base >> height >> waterVolume;
  double waterHeight = waterVolume / base / base;
  if (waterHeight * 2.0 > height) {
    height = (height - waterHeight) * 2.0;
    if (height == 0) {
      throw;
    }
    waterHeight = height / 2.0;
  }
  double waterArea = waterHeight * base;
  double ret = atan(2.0 * waterArea / height / height);
  ret = 90.0 - (ret / M_PI * 180.0);
  cout << setprecision(20) << ret << '\n';

  return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  double base, height, waterVolume;
  cin >> base >> height >> waterVolume;
  double waterHeight = waterVolume / base / base;
  if (waterHeight * 2.0 > height) {
    height = (height - waterHeight) * 2.0;
    if (abs(height) <= 1e-10) {
      cout << "0\n";
      return 0;
    }
    waterHeight = height / 2.0;
  }
  double waterArea = waterHeight * base;
  double ret = atan(2.0 * waterArea / height / height);
  ret = 90.0 - (ret / M_PI * 180.0);
  cout << setprecision(20) << ret << '\n';

  return 0;
}
Problem p02882 (C++)

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

int main() {
  double a, b, x;
  cin >> a >> b >> x;
  double delta = M_PI / pow(2, 28);
  double capa;
  double ans;

  if (a * a * b / 2 < x) {
    for (double theta = 0; tan(theta) <= (b / a); theta += delta) {
      capa = a * a * b - 0.5 * a * a * a * tan(theta);

      if (x >= capa) {
        ans = theta;
        break;
      }
    }
  } else {
    for (double theta = atan(b / a); theta <= M_PI / 2; theta += delta) {
      capa = 0.5 * a * b * b / tan(theta);
      if (x >= capa) {
        ans = theta;
        break;
      }
    }
  }

  printf("%lf\n", ans * 180 / M_PI);
}


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

int main() {
  double a, b, x;
  cin >> a >> b >> x;
  double delta = M_PI / pow(2, 26);
  double capa;
  double ans;

  if (a * a * b / 2 < x) {
    for (double theta = 0; tan(theta) <= (b / a); theta += delta) {
      capa = a * a * b - 0.5 * a * a * a * tan(theta);

      if (x >= capa) {
        ans = theta;
        break;
      }
    }
  } else {
    for (double theta = atan(b / a); theta <= M_PI / 2; theta += delta) {
      capa = 0.5 * a * b * b / tan(theta);
      if (x >= capa) {
        ans = theta;
        break;
      }
    }
  }

  printf("%lf\n", ans * 180 / M_PI);
}
Problem p02882 (Python)

Buggy submission (status: Runtime Error):
from math import atan, degrees


def main():
    a, b, x = map(int, input().split())

    full = a * a * b
    half = full * 0.5

    if x <= half:
        s = x / a
        ans = 90 - degrees(atan(2 * s / b**2))

    else:
        s = (full - x) / a
        ans = 90 - degrees(atan(a**2 / (2 * s)))

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
from math import atan, degrees


def main():
    a, b, x = map(int, input().split())

    full = a * a * b
    half = full * 0.5

    if x <= half:
        s = x / a
        ans = 90 - degrees(atan(2 * s / b**2))

    else:
        s = (full - x) / a
        if s != 0:
            ans = 90 - degrees(atan(a**2 / (2 * s)))
        else:
            ans = 0

    print(ans)


if __name__ == "__main__":
    main()
Problem p02882 (Python)

Buggy submission (status: Runtime Error):
from sys import stdin
import math

a, b, x = [int(x) for x in stdin.readline().rstrip().split()]

if 2 * x >= (a**2) * b:
    v = (a**2) * b - x
    c = (2 * v) / (a**2)
    print(90 - math.atan(a / c) * 180 / math.pi)
else:
    c = 2 * x / (a * b)
    print(math.atan(b / c) * 180 / math.pi)


Fixed submission:
from sys import stdin
import math

a, b, x = [int(x) for x in stdin.readline().rstrip().split()]

if x == (a**2) * b:
    print(0)
    exit()
if 2 * x >= (a**2) * b:
    v = (a**2) * b - x
    c = (2 * v) / (a**2)
    print(90 - math.atan(a / c) * 180 / math.pi)
else:
    c = 2 * x / (a * b)
    print(math.atan(b / c) * 180 / math.pi)
Problem p02882 (Python)

Buggy submission (status: Runtime Error):
import math

a, b, x = map(int, input().split())

b_1 = x / (a**2)
area_1 = a * b_1
area_2 = (a * b) / 2

if area_2 > area_1:
    # 三角形
    h = (a * b_1 * 2) / b
    ans = math.degrees(math.atan(h / b))
else:
    # 梯形
    upside_len = b_1 * 2 - b
    ans = math.degrees(math.atan(a / (b - upside_len)))

print(90 - ans)


Fixed submission:
import math

a, b, x = map(int, input().split())

b_1 = x / (a**2)
area_1 = a * b_1
area_2 = (a * b) / 2

if b_1 == b:
    ans = 90
elif area_2 > area_1:
    # 三角形
    h = (a * b_1 * 2) / b
    ans = math.degrees(math.atan(h / b))
else:
    # 梯形
    upside_len = b_1 * 2 - b
    ans = math.degrees(math.atan(a / (b - upside_len)))

print(90 - ans)
Problem p02882 (C++)

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

int main() {

  cout << fixed;
  cout << setprecision(10);

  long double a, b;
  long double x, y;
  cin >> a >> b >> x;
  y = a * a * b;

  long double xx, yy;
  xx = x / a;
  yy = y / a;

  long double h, w, theta;
  h = b - x / (a * a);

  if (h > b / 2.0) {
    long double d = 0.0, u = 90.0;
    int i = 0;
    while (i < 10000000) {
      theta = (d + u) / 2.0;
      // if (abs(xx - a * a * tan(theta * M_PI / 180.0) / 2.0) < EPS) break;
      if (b / tan(theta * M_PI / 180.0) * b / 2.0 < xx)
        u = theta;
      else
        d = theta;
      i++;
    }
    // w = 2.0 * xx / h;
    // theta = atan2(w , h);
    // cout << (M_PI / 2.0 - theta) / M_PI * 180.0;
    cout << theta;
    return 0;
  } else {
    w = a;
    theta = atan2(2.0 * h, w);
    cout << theta / M_PI * 180.0;
    return 0;
  }

  return 0;
}


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

int main() {

  cout << fixed;
  cout << setprecision(10);

  long double a, b;
  long double x, y;
  cin >> a >> b >> x;
  y = a * a * b;

  long double xx, yy;
  xx = x / a;
  yy = y / a;

  long double h, w, theta;
  h = b - x / (a * a);

  if (h > b / 2.0) {
    long double d = 0.0, u = 90.0;
    int i = 0;
    while (i < 10000000) {
      theta = (d + u) / 2.0;
      if (abs(xx - b / tan(theta * M_PI / 180.0) * b / 2.0) < EPS)
        break;
      if (b / tan(theta * M_PI / 180.0) * b / 2.0 < xx)
        u = theta;
      else
        d = theta;
      i++;
    }
    // w = 2.0 * xx / h;
    // theta = atan2(w , h);
    // cout << (M_PI / 2.0 - theta) / M_PI * 180.0;
    cout << theta;
    return 0;
  } else {
    w = a;
    theta = atan2(2.0 * h, w);
    cout << theta / M_PI * 180.0;
    return 0;
  }

  return 0;
}
Problem p02882 (Python)

Buggy submission (status: Runtime Error):
# -*- coding: utf-8 -*-


def main():
    from math import degrees, atan

    a, b, x = map(int, input().split())
    h = x / (a**2)
    y = 2 * h * a / b
    z = 2 * b - 2 * h

    if 2 * h >= b:
        print(90 - degrees(atan(a / z)))
    else:
        print(degrees(atan(b / y)))


if __name__ == "__main__":
    main()


Fixed submission:
# -*- coding: utf-8 -*-


def main():
    from math import degrees, atan

    a, b, x = map(int, input().split())
    h = x / (a**2)
    y = 2 * h * a / b
    z = 2 * b - 2 * h

    if x == (a**2) * b:
        print(0)
    elif 2 * h >= b:
        print(90 - degrees(atan(a / z)))
    else:
        print(degrees(atan(b / y)))


if __name__ == "__main__":
    main()
Problem p02882 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const ll INF = mod * mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
ll min(ll a, ll b) {
  if (a > b) {
    return b;
  } else {
    return a;
  }
}

ll max(ll a, ll b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}

ll power(ll a, ll b) {
  ll ans = 1;
  for (ll i = 1; i <= b; i++) {
    ans *= a;
  }
  return ans;
}

ll gcd(ll m, ll n) {
  if (n == 0) {
    return m;
  }
  return gcd(n, m % n);
}
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / gcd(a, b) * b;
}
int main() {

  double a, b, x;
  cin >> a >> b >> x;

  double h = (2 * x) / (a * b * 1.0);
  double pi;
  pi = 4.0 * atan(1.0); /* πの値 */

  double unit_r = 180.0 / pi; /* ラジアン → 度 */
  double atan(double t);

  if (h <= a) {
    return 1;
    printf("%0.10lf\n", 1.0 * atan(b / a) * unit_r);

  } else {
    printf("%0.10lf\n",
           1.0 * atan((2 * b * pow(a, 2) - 2 * x) / pow(a, 3)) * unit_r);
  }

  // cout<<pi<<endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const ll INF = mod * mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
ll min(ll a, ll b) {
  if (a > b) {
    return b;
  } else {
    return a;
  }
}

ll max(ll a, ll b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}

ll power(ll a, ll b) {
  ll ans = 1;
  for (ll i = 1; i <= b; i++) {
    ans *= a;
  }
  return ans;
}

ll gcd(ll m, ll n) {
  if (n == 0) {
    return m;
  }
  return gcd(n, m % n);
}
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / gcd(a, b) * b;
}
int main() {

  double a, b, x;
  cin >> a >> b >> x;

  double h = (2 * x) / (a * b * 1.0);
  double pi;
  pi = 4.0 * atan(1.0); /* πの値 */

  double unit_r = 180.0 / pi; /* ラジアン → 度 */
  double atan(double t);

  if (h <= a) {
    // return 1;
    printf("%0.10lf\n", 1.0 * atan(b / h) * unit_r);

  } else {
    printf("%0.10lf\n",
           1.0 * atan((2 * b * pow(a, 2) - 2 * x) / pow(a, 3)) * unit_r);
  }

  // cout<<pi<<endl;
}
Problem p02882 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  const double PI = 3.14159265358979;
  double a, b, x;
  cin >> a >> b >> x;
  double lo = 0., hi = 90.;
  for (int i = 0; i < 100000; i++) {
    double mid = lo + (hi - lo) / 2.;
    double theta = (90 - mid) / 180 * PI;
    double r = sqrt(2 * x / (a * tan(theta)));
    double t = r * tan(theta);
    if (t > a) {
      double k = t - a;
      double v = a * k * k / tan(theta) / 2;
      double u = v / (a * a);
      r += u;
    }
    if (r > b)
      hi = mid;
    else
      lo = mid;
  }
  printf("%.15f\n", lo);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  const double PI = 3.14159265358979;
  double a, b, x;
  cin >> a >> b >> x;
  double lo = 0., hi = 90.;
  for (int i = 0; i < 1000; i++) {
    double mid = lo + (hi - lo) / 2.;
    double theta = (90 - mid) / 180 * PI;
    double r = sqrt(2 * x / (a * tan(theta)));
    double t = r * tan(theta);
    if (t > a) {
      double k = t - a;
      double v = a * k * k / tan(theta) / 2;
      double u = v / (a * a);
      r += u;
    }
    if (r > b)
      hi = mid;
    else
      lo = mid;
  }
  printf("%.15f\n", lo);
  return 0;
}
Problem p02882 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  const double PI = 3.14159265358979;
  double a, b, x;
  cin >> a >> b >> x;
  double lo = 0., hi = 90.;
  for (int i = 0; i < 100000; i++) {
    double mid = lo + (hi - lo) / 2.;
    double theta = (90 - mid) / 180 * PI;
    double r = sqrt(2 * x / (a * tan(theta)));
    double t = r * tan(theta);
    if (t > a) {
      double k = t - a;
      double v = a * k * k / tan(theta) / 2;
      double u = v / (a * a);
      r += u;
    }
    if (r > b)
      hi = mid;
    else
      lo = mid;
  }
  printf("%.15f\n", lo);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  const double PI = 3.14159265358979;
  double a, b, x;
  cin >> a >> b >> x;
  double lo = 0., hi = 90.;
  for (int i = 0; i < 10000; i++) {
    double mid = lo + (hi - lo) / 2.;
    double theta = (90 - mid) / 180 * PI;
    double r = sqrt(2 * x / (a * tan(theta)));
    double t = r * tan(theta);
    if (t > a) {
      double k = t - a;
      double v = a * k * k / tan(theta) / 2;
      double u = v / (a * a);
      r += u;
    }
    if (r > b)
      hi = mid;
    else
      lo = mid;
  }
  printf("%.15f\n", lo);
  return 0;
}
Problem p02882 (C++)

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

signed main() {
  int a, b, x;
  cin >> a >> b >> x;
  double v = a * a * b, s;
  const double k = 360 / (2 * 3.141592653589793);
  double ans, c;
  if (x > v / 2) {
    s = v - x;
    double l = 2 * s / (a * a);
    c = l / a;
  } else {
    s = x;
    double l = 2 * s / (a * b);
    c = b / l;
  }
  for (int i = 1; i < 1580000000; i += 25) {
    ans = i / 1000000000.0;
    if (c - tan(ans) < 0.000000001) {
      printf("%.10lf\n", ans * k);
      return 0;
    }
  }
}


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

signed main() {
  int a, b, x;
  cin >> a >> b >> x;
  double v = a * a * b, s;
  const double k = 360 / (2 * 3.141592653589793);
  double ans, c;
  if (x > v / 2) {
    s = v - x;
    double l = 2 * s / (a * a);
    c = l / a;
  } else {
    s = x;
    double l = 2 * s / (a * b);
    c = b / l;
  }
  printf("%.10lf\n", atan(c) * k);
}
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;
typedef long long int ll;
typedef pair<int, int> P;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<ll> a(n), f(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> f[i];
  sort(a.rbegin(), a.rend());
  sort(f.begin(), f.end());
  ll ng = -1, ok = 1e12;
  while (ok - ng > 1) {
    ll mid = (ok + ng) / 2;
    ll cost = 0;
    rep(i, n) { cost += max(a[i] - min(a[i], mid / f[i]), 0LL); }
    if (cost <= k)
      ok = mid;
    else
      ng = mid;
  }
  cout << ok << endl;
  return 0;
}


Fixed submission:
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> a(n), f(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> f[i];
  sort(a.rbegin(), a.rend());
  sort(f.begin(), f.end());
  ll ng = -1, ok = 1e12;
  while (ok - ng > 1) {
    ll mid = (ok + ng) / 2;
    ll cost = 0;
    rep(i, n) { cost += max(a[i] - min(a[i], mid / f[i]), 0LL); }
    if (cost <= k)
      ok = mid;
    else
      ng = mid;
  }
  cout << ok << endl;
  return 0;
}
Problem p02883 (C++)

Buggy submission (status: Runtime Error):
/************************************************
 *Author        :  xzj213
 *Created Time  :  2019.10.27.20:59
 *Mail          :  xzj213@qq.com
 *Problem       :  E
 ************************************************/
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn], f[maxn], l, r, n, k;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch > 57 || ch < 48) {
    if (ch == 45)
      f = -1;
    ch = getchar();
  }
  while (ch <= 57 && ch >= 48) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  return x * f;
}
bool check(int point) {
  int num = k;
  for (int i = 1; i <= n; i++) {
    int b = point / f[i];
    if (a[i] - b > 0)
      num -= (a[i] - b);
    if (num < 0)
      return false;
  }
  return true;
}
bool cmp(int a, int b) { return a > b; }
signed main() {
  n = read();
  k = read();
  for (int i = 1; i <= n; i++)
    a[i] = read();
  for (int i = 1; i <= n; i++)
    f[i] = read();
  sort(a + 1, a + 1 + n);
  sort(f + 1, f + 1 + n, cmp);
  l = 0;
  r = 1e18;
  while (l < r) {
    int Mid = (l + r) >> 1;
    if (check(Mid))
      r = Mid;
    else
      l = Mid + 1;
  }
  cout << r << endl;
  return 0;
}


Fixed submission:
/************************************************
 *Author        :  xzj213
 *Created Time  :  2019.10.27.20:59
 *Mail          :  xzj213@qq.com
 *Problem       :  E
 ************************************************/
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 2e5 + 5;
int a[maxn], f[maxn], l, r, n, k;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch > 57 || ch < 48) {
    if (ch == 45)
      f = -1;
    ch = getchar();
  }
  while (ch <= 57 && ch >= 48) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  return x * f;
}
bool check(int point) {
  int num = k;
  for (int i = 1; i <= n; i++) {
    int b = point / f[i];
    if (a[i] - b > 0)
      num -= (a[i] - b);
    if (num < 0)
      return false;
  }
  return true;
}
bool cmp(int a, int b) { return a > b; }
signed main() {
  n = read();
  k = read();
  for (int i = 1; i <= n; i++)
    a[i] = read();
  for (int i = 1; i <= n; i++)
    f[i] = read();
  sort(a + 1, a + 1 + n);
  sort(f + 1, f + 1 + n, cmp);
  l = 0;
  r = 1e18;
  while (l < r) {
    int Mid = (l + r) >> 1;
    if (check(Mid))
      r = Mid;
    else
      l = Mid + 1;
  }
  cout << r << endl;
  return 0;
}
Problem p02883 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template <typename T> vector<T> make_v(size_t a, T b) {
  return vector<T>(a, b);
}

template <typename... Ts> auto make_v(size_t a, Ts... ts) {
  return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> 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(), [](ll x, ll y) { return x > y; });

  auto check = [&](ll x) {
    ll t = 0;

    REP(i, n) { t += max(0LL, a[i] - x / f[i]); }

    return t <= k;
  };

  ll l = -1, r = 1e18;
  while (r - l > 1) {
    ll m = (l + r) / 2;
    if (check(m)) {
      r = m;
    } else {
      l = m;
    }
  }

  cout << r << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template <typename T> vector<T> make_v(size_t a, T b) {
  return vector<T>(a, b);
}

template <typename... Ts> auto make_v(size_t a, Ts... ts) {
  return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> 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(), [](ll x, ll y) { return x > y; });

  auto check = [&](ll x) {
    ll t = 0;

    REP(i, n) { t += max(0LL, a[i] - x / f[i]); }

    return t <= k;
  };

  ll l = -1, r = 1e18;
  while (r - l > 1) {
    ll m = (l + r) / 2;
    if (check(m)) {
      r = m;
    } else {
      l = m;
    }
  }

  cout << r << endl;

  return 0;
}
Problem p02883 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 100100;
int a[maxn], f[maxn];

ll check(int n, ll t) {
  ll ret = 0;
  for (int i = 1; i <= n; i++) {
    ret += max(0ll, a[i] - t / f[n - i + 1]);
  }
  return ret;
}

int main(void) {
  int n;
  ll k;
  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);
  ll l = 0, r = 1e12, ans = r;
  while (l <= r) {
    ll mid = (l + r) / 2;
    if (check(n, mid) <= k) {
      ans = min(ans, mid), r = mid - 1;
    } else
      l = mid + 1;
  }
  printf("%lld\n", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 200100;
int a[maxn], f[maxn];

ll check(int n, ll t) {
  ll ret = 0;
  for (int i = 1; i <= n; i++) {
    ret += max(0ll, a[i] - t / f[n - i + 1]);
  }
  return ret;
}

int main(void) {
  int n;
  ll k;
  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);
  ll l = 0, r = 1e12, ans = r;
  while (l <= r) {
    ll mid = (l + r) / 2;
    if (check(n, mid) <= k) {
      ans = min(ans, mid), r = mid - 1;
    } else
      l = mid + 1;
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p02883 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
int N_MAX = 20000;
int main() {
  long long a[N_MAX], f[N_MAX];
  long long n, k, i, t, s = 0, p, l = 0, r = 0;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
  }
  for (i = 0; i < n; i++)
    cin >> f[i];
  if (k >= s) {
    cout << "0" << endl;
    return 0;
  }
  sort(a, a + n);
  sort(f, f + n, greater<long long>());
  for (i = 0; i < n; i++) {
    t = a[i] * f[i];
    r = max(t, r);
  }
  while (r > l + 1) {
    t = 0;
    p = (l + r) / 2;
    for (i = 0; i < n; i++)
      t += max(a[i] - p / f[i], (long long)0);
    if (t <= k)
      r = p;
    else
      l = p;
  }
  cout << r << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
int N_MAX = 200000;
int main() {
  long long a[N_MAX], f[N_MAX];
  long long n, k, i, t, s = 0, p, l = 0, r = 0;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
  }
  for (i = 0; i < n; i++)
    cin >> f[i];
  if (k >= s) {
    cout << "0" << endl;
    return 0;
  }
  sort(a, a + n);
  sort(f, f + n, greater<long long>());
  for (i = 0; i < n; i++) {
    t = a[i] * f[i];
    r = max(t, r);
  }
  while (r > l + 1) {
    t = 0;
    p = (l + r) / 2;
    for (i = 0; i < n; i++)
      t += max(a[i] - p / f[i], (long long)0);
    if (t <= k)
      r = p;
    else
      l = p;
  }
  cout << r << endl;
  return 0;
}
Problem p02883 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int maxV = 90010;
const int maxN = 2e5 + 10;
const int MOD = 1e9 + 7;
const ll INF = 1000000000000000010LL;
const int inf = 1e9 + 10;
#define X first;
#define Y second;

ll a[maxN];
ll f[maxN];
int n;
bool check(ll x, ll k) {
  for (int i = 1; i <= n; i++) {
    if (a[i] * f[i] > x) {
      ll cnt = (a[i] * f[i] - x);
      if (cnt % f[i] == 0) {
        cnt /= f[i];
      } else {
        cnt = cnt / f[i] + 1;
      }
      if (k >= cnt) {
        k -= cnt;
      } else
        return false;
    }
  }
  if (k >= 0)
    return true;
  else
    return false;
}
int main() {
  ll k;
  scanf("%d %lld", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &f[i]);
  }
  sort(a + 1, a + 1 + n);
  sort(f + 1, f + 1 + n);
  reverse(f + 1, f + 1 + n);
  ll R = 0;
  for (int i = 1; i <= n; i++) {
    R = max(a[i] * f[i], R);
  }
  ll L = 0;
  ll ans = 0;
  while (L <= R) {
    int mid = (L + R) / 2;
    if (check(mid, k)) {
      ans = mid;
      R = mid - 1;
    } else {
      L = mid + 1;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int maxV = 90010;
const int maxN = 2e5 + 10;
const int MOD = 1e9 + 7;
const ll INF = 1000000000000000010LL;
const int inf = 1e9 + 10;
#define X first;
#define Y second;

ll a[maxN];
ll f[maxN];
int n;
bool check(ll x, ll k) {
  for (int i = 1; i <= n; i++) {
    if (a[i] * f[i] > x) {
      ll cnt = (a[i] * f[i] - x);
      if (cnt % f[i] == 0) {
        cnt /= f[i];
      } else {
        cnt = cnt / f[i] + 1;
      }
      if (k >= cnt) {
        k -= cnt;
      } else
        return false;
    }
  }
  if (k >= 0)
    return true;
  else
    return false;
}
int main() {
  ll k;
  scanf("%d %lld", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &f[i]);
  }
  sort(a + 1, a + 1 + n);
  sort(f + 1, f + 1 + n);
  reverse(f + 1, f + 1 + n);
  ll R = 0;
  for (int i = 1; i <= n; i++) {
    R = max(a[i] * f[i], R);
  }
  ll L = 0;
  ll ans = 0;
  while (L <= R) {
    ll mid = (L + R) / 2;
    if (check(mid, k)) {
      ans = mid;
      R = mid - 1;
    } else {
      L = mid + 1;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02883 (C++)

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

using namespace std;
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
typedef long long ll;
const int mn = 1e5 + 5;
typedef pair<ll, int> pii;
int n;
ll k, ans;
int a[mn], f[mn];

bool c(ll x) {
  ll tk = k;
  for (int i = 1; i <= n; i++) {
    if (1ll * a[i] * f[i] <= x)
      continue;
    int needa = x / f[i];
    tk -= (a[i] - needa);
  }
  return tk >= 0;
}

int main() {
  // cin.sync_with_stdio(0);
#ifdef trote
  freopen("../1.txt", "r", stdin);
#endif
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &f[i]);
  }
  sort(f + 1, f + n + 1, [](int a, int b) { return a > b; });
  ll L = 0, R = n * 1000000000000ll, ans = 0;
  while (L <= R) {
    ll mid = L + R >> 1;
    if (c(mid))
      R = mid - 1, ans = mid;
    else
      L = mid + 1;
  }
  printf("%lld\n", ans);
  return 0;
}

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

using namespace std;
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
typedef long long ll;
const int mn = 1e6 + 5;
typedef pair<ll, int> pii;
int n;
ll k, ans;
int a[mn], f[mn];

bool c(ll x) {
  ll tk = k;
  for (int i = 1; i <= n; i++) {
    if (1ll * a[i] * f[i] <= x)
      continue;
    int needa = x / f[i];
    tk -= (a[i] - needa);
  }
  return tk >= 0;
}

int main() {
  // cin.sync_with_stdio(0);
#ifdef trote
  freopen("../1.txt", "r", stdin);
#endif
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &f[i]);
  }
  sort(f + 1, f + n + 1, [](int a, int b) { return a > b; });
  ll L = 0, R = n * 1000000000000ll, ans = 0;
  while (L <= R) {
    ll mid = L + R >> 1;
    if (c(mid))
      R = mid - 1, ans = mid;
    else
      L = mid + 1;
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p02883 (Python)

Buggy submission (status: Time Limit Exceeded):
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
F = sorted(list(map(int, input().split())))


def binary_search(min_n, max_n):
    while max_n - min_n != 1:
        tn = (min_n + max_n) // 2
        if judge(tn):
            max_n = tn
        else:
            min_n = tn

    return max_n


def judge(tn):
    k = 0
    for i in range(N):
        if A[i] * F[i] > tn:
            k += A[i] - (tn // F[i])
        if k > K:
            return False

    return True


def solve():
    ans = binary_search(-1, 10**12)
    print(ans)


if __name__ == "__main__":
    solve()


Fixed submission:
import sys

input = lambda: sys.stdin.readline().rstrip()

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


def binary_search(min_n, max_n):
    while max_n - min_n != 1:
        tn = (min_n + max_n) // 2
        if judge(tn):
            max_n = tn
        else:
            min_n = tn

    return max_n


def judge(tn):
    k = 0
    for i in range(N):
        if A[i] * F[i] > tn:
            k += A[i] - (tn // F[i])
        if k > K:
            return False

    return True


def solve():
    ans = binary_search(-1, 10**12)
    print(ans)


if __name__ == "__main__":
    solve()
Problem p02883 (C++)

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

typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

// cout<<fixed<<setprecision(10);
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

const int NM = 2 * 1e5;

int ar[NM];
int fr[NM];

int main() {
  int n, k;
  cin >> n >> k;
  rep(i, n) {
    int a;
    cin >> a;
    ar[i] = a; // 消化コスト
  }
  rep(i, n) {
    int a;
    cin >> a;
    fr[i] = a; // 食べにくさ
  }
  sort(ar, ar + n);
  sort(fr, fr + n, greater<int>());

  // へらす
  ll l = -1;
  ll r = 1e12;
  while (l + 1 < r) {
    ll mid = (l + r) / 2;
    //
    bool isOk = [&] {
      ll s = 0;
      rep(i, n) { s += max(0ll, ar[i] - mid / fr[i]); }
      return s <= k;
    }();
    if (isOk)
      r = mid;
    else
      l = mid;
  }

  cout << r << endl;
}

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

typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

// cout<<fixed<<setprecision(10);
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

const int NM = 2 * 1e5;

int ar[NM];
int fr[NM];

int main() {
  int n;
  ll k;
  cin >> n >> k;
  rep(i, n) {
    int a;
    cin >> a;
    ar[i] = a; // 消化コスト
  }
  rep(i, n) {
    int a;
    cin >> a;
    fr[i] = a; // 食べにくさ
  }
  sort(ar, ar + n);
  sort(fr, fr + n, greater<int>());

  // へらす
  ll l = -1;
  ll r = 1e12;
  while (l + 1 < r) {
    ll mid = (l + r) / 2;
    //
    bool isOk = [&] {
      ll s = 0;
      rep(i, n) { s += max(0ll, ar[i] - mid / fr[i]); }
      return s <= k;
    }();
    if (isOk)
      r = mid;
    else
      l = mid;
  }

  cout << r << endl;
}