Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
521 B
3
Indexable
Never
#include <bits/stdc++.h>

using namespace std;
#define ll long long

int main() {
  int n, m; cin >> n >> m;
  vector<ll> t(n);
  for(int i = 0; i < n; i++) cin >> t[i];

  auto ok = [&](ll x) {
    ll nop = 0;
    for(int i = 0; i < n; i++) {
      nop += x / t[i];
    }
    return nop >= m;
  };

  ll l = 0, r = (ll)(1e18), mid, best;
  while(l <= r) {
    mid = (r - l) / 2 + l;
    if(ok(mid)) {
      best = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }

  cout << best << endl;

  return 0;
}