#include <bits/stdc++.h> #define int long long #define For(i, l, r) for (int i = l; i <= r; i++) using namespace std; const int M = 200005, inf=1e9; int n, a[M], t; bool check(int x){ int y=0; For(i, 1, n){ bool ok=0; For(z, 0, x-y){ if (z*(z*(z*(-2)+3*x-6*y)+6*x*y-3*x-6*y*y+2)>=6*a[i]){ y+=z; ok=1; break; } } if (!ok){ return 0; } } return 1; } void solve(){ cin>>n; int sum=0; For(i, 1, n){ cin>>a[i]; sum+=a[i]; } int f=3, l=30'000'000; while(f<l){ int m=(f+l)/2; if (check(m)) l=m; else f=m+1; } cout << f<<'\n'; } signed main() { cin.tie(0)->sync_with_stdio(); int t; cin>>t; For(_, 1, t) solve(); }
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 | #include <bits/stdc++.h> #define int long long #define For(i, l, r) for (int i = l; i <= r; i++) using namespace std; const int M = 200005, inf=1e9; int n, a[M], t; bool check(int x){ int y=0; For(i, 1, n){ bool ok=0; For(z, 0, x-y){ if (z*(z*(z*(-2)+3*x-6*y)+6*x*y-3*x-6*y*y+2)>=6*a[i]){ y+=z; ok=1; break; } } if (!ok){ return 0; } } return 1; } void solve(){ cin>>n; int sum=0; For(i, 1, n){ cin>>a[i]; sum+=a[i]; } int f=3, l=30'000'000; while(f<l){ int m=(f+l)/2; if (check(m)) l=m; else f=m+1; } cout << f<<'\n'; } signed main() { cin.tie(0)->sync_with_stdio(); int t; cin>>t; For(_, 1, t) solve(); } |