题目链接:https://ac.nowcoder.com/acm/problem/19916
题目大意:
#include <bits/stdc++.h> #define LL long long using namespace std; LL a[55]; LL n, m; LL check(LL mid){ LL ans=0; for(int i=1; i<=n; i++){ if(a[i]<=mid){ ans+=mid-a[i]; } } if(ans>m||ans>mid){ return 0; } else{ return 1; } } int main(){ scanf("%lld%lld", &n, &m); for(int i=1; i<=n; i++){ scanf("%d", &a[i]); } LL L=0, R=1ll<<50, k=0; while(L<=R){ LL mid=L+R>>1; if(check(mid)){ L=mid+1; k=mid; } else{ R=mid-1; } } printf("%lld\n", k); return 0; }