4 条题解

  • 0
    @ 2024-4-10 0:30:08

    普普通通二分题 我叫你开longlong你二龙嘛

    #define _CRT_SECURE_NO_WARNINGS 1
    /**
     * @brief 打开宏开关
     * */
    #define _USE_MATH_DEFINES
    #include <cmath>
    #include <bits/stdc++.h>
    using namespace std;
    #define ll long long
    
    const int N = 1e6 + 5;
    ll n, m;
    ll a[N];
    bool bisearch(ll h)
    {
    	ll sum = 0;
    	for (int i = 1; i <= n; i++)
    	{
    		if (a[i] > h) sum += a[i] - h;
    	}
    	return sum >= m;
    }
    int main()
    {
    	cin >> n >> m;
    	for (int i = 1; i <= n; i++)
    		cin >> a[i];
    	ll l = 1, r = 1e9;
    	while (l + 1 < r)
    	{
    		ll m = l + r >> 1;
    		if (bisearch(m)) l = m;
    		else r = m;
    	}
    	if (bisearch(l)) cout << l;
    	else cout << r;
    	return 0;
    }
    

    信息

    ID
    89
    时间
    1000ms
    内存
    256MiB
    难度
    7
    标签
    递交数
    925
    已通过
    205
    上传者