传送门:https://www.luogu.com.cn/problem/CF2232B
有一个很显然的模拟,枚举当前可能最大值和余量,如果余量不足以填平下一个到可能最大值就重置可能最大值到前缀平均值。进一步地有结论,前缀答案即为前缀平均值最小值,
#include <bits/stdc++.h>#define int long longusing namespace std;void solve() {int n;cin >> n;int x1;cin >> x1;cout << x1 << ' ';int now = x1, ad = 0, sum = x1;for (int i = 2; i <= n; ++i) {int x;cin >> x;sum += x;if (x + ad < now) now = sum / i, ad = sum % i;else ad += x - now;cout << now << ' ';}cout << '\n';
}signed main() {ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);int T;cin >> T;while (T--) solve();return 0;
}
