제출 #1123461

#제출 시각아이디문제언어결과실행 시간메모리
1123461ramzialoulouSelf Study (JOI22_ho_t2)C++20
62 / 100
163 ms5092 KiB
#include <bits/stdc++.h>

using namespace std;

#ifdef Ramzi
#include "debug.h"
#else
#define debug(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<int64_t> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int64_t> b(n);
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  auto check = [&](int64_t mid) -> bool {
    int64_t tot = n * m;
    for (int i = 0; i < n; i++) {
      int64_t s = 0;
      if (a[i] > b[i]) {
        int64_t req = (mid + a[i] - 1) / a[i];
        if (req <= m) {
          tot -= req;
        } else {
          int64_t rem = mid - m * a[i];
          tot -= m;
          tot -= (rem + b[i] - 1) / b[i];
        }
      } else {
        int64_t req = (mid + b[i] - 1) / b[i];
        tot -= req;
      }
      if (tot < 0) {
        return false;
      }
    }
    return true;
  };
  int64_t lo = 0, hi = int64_t(1e18), ans = 0;
  while (lo <= hi) {
    int64_t mid = (lo + hi) >> 1;
    if (check(mid)) {
      ans = mid;
      lo = mid + 1;
    } else {
      hi = mid - 1;
    }
  }
  cout << ans << "\n";
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...