2141. 同时运行 N 台电脑的最长时间
2022-01-20 本文已影响0人
来到了没有知识的荒原
2141. 同时运行 N 台电脑的最长时间

class Solution {
public:
typedef long long ll;
bool check(vector<int> &bs,ll t, ll n) {
ll sum=0;
for(auto s:bs)sum+=min(1ll*s,t);
return sum/t>=n;
}
long long maxRunTime(int n, vector<int>& bs) {
ll sum=0;
for(auto s:bs) sum+=s;
ll l=0,r=sum;
while(l<r){
ll mid=l+r+1>>1;
if(check(bs,mid,n))l=mid;
else r=mid-1;
}
return l;
}
};