#include <bits/stdc++.h> using namespace std; vector < long long int> a; long long int n,d,t,i,j,b,x,ax,bx; long long int m,m2,y,L,P,c,tt,e,Sb,Lb,Pb,S; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> t; for(i=0;i<t;i++) { cin >> n; a={}; for(j=0;j<n;j++) { cin >> c; if(c>0) a.push_back(6*c); } P=200*a.size(); L=0; while (L<P){ S=(L+P)/2; x=0; e=0; for(auto b: a) { Lb=1; Pb=S-x+1; ax=(2 - 3*S+6*S*x-6*x*x); bx=(S-2*x); while(Lb<Pb){ Sb=(Lb+Pb)/2; if ((ax+Sb*(3*bx -2*Sb))<=(b-1)/Sb) Lb=Sb+1; else Pb=Sb; if( Lb==S-x+1){ e=1; break; }} x+=Lb ; } if( e) L=S+1; else P=S; } cout << L <<'\n'; } }
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> using namespace std; vector < long long int> a; long long int n,d,t,i,j,b,x,ax,bx; long long int m,m2,y,L,P,c,tt,e,Sb,Lb,Pb,S; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> t; for(i=0;i<t;i++) { cin >> n; a={}; for(j=0;j<n;j++) { cin >> c; if(c>0) a.push_back(6*c); } P=200*a.size(); L=0; while (L<P){ S=(L+P)/2; x=0; e=0; for(auto b: a) { Lb=1; Pb=S-x+1; ax=(2 - 3*S+6*S*x-6*x*x); bx=(S-2*x); while(Lb<Pb){ Sb=(Lb+Pb)/2; if ((ax+Sb*(3*bx -2*Sb))<=(b-1)/Sb) Lb=Sb+1; else Pb=Sb; if( Lb==S-x+1){ e=1; break; }} x+=Lb ; } if( e) L=S+1; else P=S; } cout << L <<'\n'; } } |