제출 #1182818

#제출 시각아이디문제언어결과실행 시간메모리
1182818dima2101Self Study (JOI22_ho_t2)C++20
0 / 100
93 ms4936 KiB
#include <bits/stdc++.h>
#define int long long

bool Check(std::vector<int>& a, std::vector<int>& b, int mid, int n, int m) {
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (m * a[i] < mid) {
      cnt -= (mid - (m * a[i]) + b[i] - 1) / b[i];
    } else {
      int need = (mid + a[i] - 1) / a[i];
      need = m - need;
      assert(need >= 0);
      cnt += need;
    }
  }
  return (cnt >= 0);
}

int32_t main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  int n, m;
  std::cin >> n >> m;

  std::vector<int> a(n);
  std::vector<int> b(n);
  for (int i = 0; i < n; i++) std::cin >> a[i];
  for (int i = 0; i < n; i++) std::cin >> b[i];
  for (int i = 0; i < n; i++) {
    a[i] = std::max(a[i], b[i]);
  }

  // std::cout << Check(a, b, 18, n, m) << std::endl;
  // return 0;
  int l = 0, r = 2LL * (int)1e18;
  while (l + 1 < r) {
    int mid = (l + r) / 2;

    if (Check(a, b, mid, n, m)) {
      l = mid;
    } else {
      r = mid;
    }
  }
  assert(l != 0);
  std::cout << l;
}
#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...