#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int i = (a); i < (b); i++) #define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--) #define SZ(a) int(a.size()) #define ALL(a) a.begin(), a.end() #define PB push_back #define MP make_pair #define F first #define S second typedef long long LL; typedef vector<int> VI; typedef vector<LL> VL; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef double db; const int N = 1 << 18; int n; int a[N]; bool check(int S) { int sl = 0; FOR(i, 0, n) { LL c = 0; while (sl + c <= S && c * (c - 1) * (c - 2) / 6 + c * (c - 1) * (S - c) / 2 + sl * c * (S - sl - c) < a[i]) c++; if (sl + c > S) return false; sl += c; } return true; } void solve() { cin >> n; FOR(i, 0, n) cin >> a[i]; int l = 0, r = 1e9; while (r - l > 1) { int m = (l + r) / 2; if (check(m)) r = m; else l = m; } cout << r << "\n"; } int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { solve(); } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | #include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int i = (a); i < (b); i++) #define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--) #define SZ(a) int(a.size()) #define ALL(a) a.begin(), a.end() #define PB push_back #define MP make_pair #define F first #define S second typedef long long LL; typedef vector<int> VI; typedef vector<LL> VL; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef double db; const int N = 1 << 18; int n; int a[N]; bool check(int S) { int sl = 0; FOR(i, 0, n) { LL c = 0; while (sl + c <= S && c * (c - 1) * (c - 2) / 6 + c * (c - 1) * (S - c) / 2 + sl * c * (S - sl - c) < a[i]) c++; if (sl + c > S) return false; sl += c; } return true; } void solve() { cin >> n; FOR(i, 0, n) cin >> a[i]; int l = 0, r = 1e9; while (r - l > 1) { int m = (l + r) / 2; if (check(m)) r = m; else l = m; } cout << r << "\n"; } int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { solve(); } return 0; } |