3 solutions

  • 1
    @ 2025-3-9 20:51:30
    #include<iostream>
    #include<algorithm>
    
    using namespace std;
    int n,m,c[55];
    
    bool check(int t)
    {
        int r = min( m - t + c[1], c[1] );//min(m-(t-c[1]) , t-(t-c[1]));
        if(r < 0)return flase;
        for(int i = 2 ;i <= n;i++)
        {
            
             if( r < t - c[i])
            {
                return false;
            }
            r -= t - c[i];
          if( c[i] >= t )break;
        }
        return true;
    }
    int main()
    {
        cin>>n>>m;
        for(int i = 1;i <= n;i++)
        {
            scanf("%d",&c[i]);
        }
        sort(c + 1,c + n + 1);//进行排序
        int l =  c[1];
        int r = c[1] + c[2];
        while(l < r)//以套数作为总的边界
        {
            int mid = l + r + 1 >>1;
            if ( check(mid)== false )r = mid - 1;
            else l = mid;
        }
        cout<<l;
        return 0;
    }
    

    Information

    ID
    7013
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    4
    Tags
    (None)
    # Submissions
    174
    Accepted
    11
    Uploaded By