【每日一题】18.华华给月月准备礼物 (水题,二分)

补题链接:Here

超级基本的二分

贴个代码就溜了

using ll = long long;
void solve() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (ll &x : a) cin >> x;
    ll l = 1, r = 1e9, len;
    while (l <= r) {
        ll mid = l + r >> 1, sum = 0;
        for (int i = 0; i < n; ++i) sum += a[i] / mid;
        if (sum >= k) len = mid, l = mid + 1;
        else
            r = mid - 1;
    }
    cout << len << '\n';
}
posted @ 2021-04-29 19:51  RioTian  阅读(49)  评论(0编辑  收藏  举报