解析
二分答案数量,然后 c h e c k check check 当前的数量能否组成
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
int a,b,c,d,e;
bool check(int x){
int s=1e18;
s=min(a-x,s);
s=min(b-x,s);
s=min(c-x,s);
s=min(d-x,s);
if(s<0){
if(e<=x||e-x<abs(s)) return false;
else return true;
}
else{
if(e>=x||s>=x-e) return true;
return false;
}
}
void solve(){
cin>>a>>b>>c>>d>>e;
int l=0,r=1e18;
while(l<r){
int mid=l+r+1>>1;
if(check(mid)) l=mid;
else r=mid-1;
}
cout<<l<<endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t=1;
cin>>t;
while(t--) solve();
return 0;
}