【https://www.jisuanke.com/contest/1228/74417】
#include<bits/stdc++.h> #include<string.h> #include<cstring> #include<cstdio> #include<vector> using namespace std; #define ll long long #define ull unsigned long long #define mod 1000000007 #define inf 0x3f3f3f3f #define maxn 20005 using namespace std; ll n,a[maxn];//车数量 每辆车重量 ll p; //每辆车花费 ll s; //总预算 ll check(ll x) //设x是最重的重量 { ll sum=0; //实际预算 for(ll i=0;i<n;i++) { if(a[i]>x){ sum+=(a[i]-x)*p; } } return sum<=s; } int main() { cin >> n; ll ans; ll Max = 0; for(ll i=0;i<n;i++){ cin>>a[i]; Max = max(Max,a[i]); } cin>>p>>s; //sort(a,a+n); ll l=1, r=Max; while(l<=r) { ll mid=(l+r)/2; if(check(mid)){ ans=mid; r = mid-1; } else { l = mid+1; } } cout<<ans<<endl; }