#include <bits/stdc++.h>
using namespace std;
#define Fujiwara_Chan ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
typedef long long ll;
int main() {
Fujiwara_Chan
int tt; cin >> tt;
while (tt--) {
int n, k; cin >> n >> k;
vector<int> v(n);
for (auto &i : v) cin >> i;
ll l = *max_element(v.begin(), v.end()) + 1;
ll r = l + k, ans = l - 1;
while (l <= r) {
ll mid = (l + r) / 2, flag = 0;
for (int i = 0; i < n; ++i) {
ll cnt = 0, curr = mid;
for (int j = i; j < n; ++j) {
if (curr <= v[j]) {
if (cnt <= k) flag = 1;
break;
}
if (j == n - 1) cnt = k + 1;
cnt += curr - v[j];
curr--;
}
if (cnt <= k) flag = 1;
}
if (flag) ans = mid, l = mid + 1;
else r = mid - 1;
}
cout << ans << "\n";
}
return 0;
}
127. Word Ladder | 123. Best Time to Buy and Sell Stock III |
85. Maximal Rectangle | 84. Largest Rectangle in Histogram |
60. Permutation Sequence | 42. Trapping Rain Water |
32. Longest Valid Parentheses | Cutting a material |
Bubble Sort | Number of triangles |
AND path in a binary tree | Factorial equations |
Removal of vertices | Happy segments |
Cyclic shifts | Zoos |
Build a graph | Almost correct bracket sequence |
Count of integers | Differences of the permutations |
Doctor's Secret | Back to School |
I am Easy | Teddy and Tweety |
Partitioning binary strings | Special sets |
Smallest chosen word | Going to office |
Color the boxes | Missing numbers |