交易系统的降级策略-二分
#include <iostream>
#include <vector>
using namespace std;
int cnt;
vector<int> R;
bool check(int x) {
int res = 0;
for (int r : R) {
if (r <= x) res += r;
else res += x;
}
return res <= cnt;
}
int main()
{
int temp;
while (cin >> temp) R.push_back(temp);
cin >> cnt;
int l = 0, r = 1e5;
while (l < r) {
int mid = (l + r + 1) >> 1;
if (check(mid)) l = mid;
else r = mid - 1;
}
cout << r << endl;
return 0;
}