abc063d <二分答案>

发布时间 2023-07-08 18:45:20作者: O2iginal

D - Widespread
对二分答案的特点要敏感!!!

// https://atcoder.jp/contests/abc063/tasks/arc075_b
// 二分答案
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
int h[N];
int n, a, b;

bool check(int x)
{
    int cnt = 0;
    for (int i = 1; i <= n; i ++) 
    {
        if (1ll*x*b < h[i])
        {
            cnt += (h[i] - x*b + (a-b-1)) / (a-b);  // 注意这里是a-b, 而不是除a
        }
        if (cnt > x) return false;
    }
    return true;
}

void solv()
{
    cin >> n >> a >> b;
    int maxh = 0;
    for (int i = 1; i <= n; i ++) {
        cin >> h[i];
        maxh = max(maxh, h[i]);
    }
    int l = 0, r = maxh;
    while (l < r)
    {
        int mid = (l + r) / 2;
        if (check(mid)) r = mid;
        else l = mid + 1;
        // cout << l << "," << r << endl;
    }
    cout << l << endl;
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int T = 1;
    // cin >> T;
    while (T --)
    {
        solv();
    }
    return 0;
}