voidsolve(){ int _; cin >> _; for (int ts = 0; ts < _; ++ts) { int n, k; cin >> n >> k; vector<int> data(n); for (int i = 0; i < n; ++i) cin >> data[i]; int ans = 0; for (int i = 0; i < n; ++i) ans = max(ans, data[i]);
for (int l = 0; l < n; ++l) { int b = ans, e = ans + k + 1; while (b + 1 < e) { int mid = (b + e) / 2; int cost = 0; bool keyPoint = false; for (int i = l; i < n && !keyPoint && cost <= k; ++i) { if (data[i] >= mid - (i - l)) keyPoint = true; else cost += mid - data[i] - (i - l); } if (keyPoint && cost <= k) b = mid; else e = mid; } ans = max(ans, b); }
intdp(vector<int> &pack){ if (pack.size() == 0) { return0; } if (pack.size() == 1) { return0; } if (pack.size() == 2) { return pack[0] * pack[1]; } int sum = 0; for (int i : pack) sum += i;
vector<int> dp(sum / 2 + 1, 0); for (int i : pack) for (int w = sum / 2; w >= i; --w) dp[w] = max(dp[w], dp[w - i] + i);
int left = 0; for (auto i : dp) left = max(left, i); return left * (sum - left); }
inttree(int index, int &cal){ int res = 1; vector<int> temp; for (int i = head[index]; i != -1; i = edge[i].nxt) { temp.push_back(tree(edge[i].v, cal)); } cal += dp(temp); for (int i : temp) res += i; return res; }
voidsolve(){ int n; cin >> n;
for (int i = 0; i <= n; ++i) head[i] = -1; for (int i = 1; i < n; ++i) { int tmp; cin >> tmp; edge[i] = {i + 1, head[tmp]}; head[tmp] = i; }