其他分享
首页 > 其他分享> > 3.23题解

3.23题解

作者:互联网

小明爱玩牌

题目链接:

涉及知识点:

solution:

std:

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+10;

int n,m;
int a[N];
int l = 0;
int r = 1e10;
bool check(int x)
{
    int ans = min(m,x);
    
    for (int i = 1; i <= n; i ++ )
    {
        if(a[i] < x)
        {
           ans -= x - a[i];
        }
        if(ans < 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    int res = 0;
//    freopen("in.txt", "r", stdin);
    scanf("%d%d",&n,&m);
    for (int i = 1 ; i <= n ; i ++ ) scanf("%d",&a[i]);
    while(l <= r)
    {
        int mid = (l+r)/2;
        if(check(mid))
        {
            res = mid;
            l = mid+1;
        }
        else r = mid-1;
    }
    
    cout << res << endl;
    
    return 0;
}

标签:int,题解,万能,套牌,用到,3.23,ans,我们
来源: https://www.cnblogs.com/QFNU-ACM/p/12552211.html