Codeforces Round 890 (Div. 2) supported by Constructor Institute
C. To Become Max
Code:
#include
#include
using namespace std;
const int maxn = 1010;
int a[maxn];
int n,k;
int check(int i, int mid, int k){
if(i>n||k<0) return 0;
int used = max(0, mid-a[i]);
if(a[i] >= mid) return 1;
else return check(i+1, mid-1, k-used);
}
int main(){
int t;
cin >> t;
while(t--){
cin >> n >> k;
for(int i = 1;i <= n;i++){
cin >> a[i];
}
int ans = 0;
for(int i = 1;i <= n;i++){
int l = 0;
int r = 1e9;
while(l <= r){
int mid = (l+r)/2;
if(check(i, mid, k)) l = mid+1;
else r = mid-1;
}
ans = max(ans, l-1);
}
cout << ans << endl;
}
return 0;
}