#include #include namespace my{ using namespace atcoder; using ml=modint998244353; auto&operator<<(std::ostream&o,const ml&x){return o<>(std::istream&i,ml&x){long long t;i>>t;x=t;return i;} void main(); } int main(){my::main();} namespace my{ #define eb emplace_back #define all(a) (a).begin(),(a).end() #define RD(T,...) T __VA_ARGS__;li(__VA_ARGS__) #define LL(...) RD(ll,__VA_ARGS__) #define JO(a,b) a##b #define jo(a,b) JO(a,b) #define usymbol(a) jo(a,__LINE__) #define FE(v,e,...) for(au&&__VA_OPT__([)e __VA_OPT__(,__VA_ARGS__]):v) #define FO(n) for(ll usymbol(i)=n;usymbol(i)-->0;) #define FOR(i,...) for(au[i,i##O,i##E]=rng(0,__VA_ARGS__);i=i##O;i-=i##E) #define I template #define J class #define au auto #define rr return using namespace std; using vo=void;using bo=bool; vo solve(); Iconstexpr bo same=is_same_v; using is=istream;using os=ostream; using dd=long double;using ll=long long;using ull=unsigned long long; using lll=__int128_t;using ulll=__uint128_t;using str=string; os&operator<<(os&o,const ulll&x){rr(x<10?o:o<0?x:-x);} constexpr dd ee=1e-12; constexpr ll oo=3e18; constexpr ll dx[]{-1,0,1,0,-1,1,1,-1},dy[]{0,-1,0,1,-1,-1,1,1}; constexpr char sp=32,nl=10; au rng(bo s,ll a,ll b=oo,ll c=1){if(b==oo)b=a,(s?b:a)=0;rr tuple{a-s,b,c};} IT zz(T x){rr x<0?-x:x;} Ill len(const T&a){rr a.size();} Ibo amax(T&a,const T&b){rr aau max(const A&...a){rr max(initializer_list>{a...});} Iau min(const A&...a){rr min(initializer_list>{a...});} Istruct cp{ A a={};B b={}; cp(){} cp(A a,B b):a(a),b(b){} cp(pairp):a(p.first),b(p.second){} bo operator==(const cp&c)const{rr a==c.a&&b==c.b;} au operator<=>(const cp&c)const{rr a!=c.a?a<=>c.a:b<=>c.b;} friend is&operator>>(is&i,cp&c){rr i>>c.a>>c.b;} friend os&operator<<(os&o,const cp&c){rr o<; Istruct tr{ A a={};B b={};C c={}; tr(){} tr(A a,B b,C c):a(a),b(b),c(c){} bo operator==(const tr&t)const{rr a==t.a&&b==t.b&&c==t.c;} au operator<=>(const tr&t)const{rr a!=t.a?a<=>t.a:b!=t.b?b<=>t.b:c<=>t.c;} friend is&operator>>(is&i,tr&t){rr i>>t.a>>t.b>>t.c;} friend os&operator<<(os&o,const tr&t){rr o<; Iusing ar=array; Ios&operator<<(os&o,const ar&a){fo(i,n)o<using map=std::map; Ios&operator<<(os&o,const map&m){fe(m,e)o<using umap=unordered_map; Ios&operator<<(os&o,const umap&m){fe(m,e)o<using bset=bitset; Ios&operator<<(os&o,const bset&b){fo(i,n)o<os&operator<<(os&o,const tuple&t){apply([&](const au&...a){ll i=sizeof...(a);(((o<0,sp))),...);},t);rr o;} Istruct prique:priority_queue,F>{ prique(const initializer_list&a={}){fe(a,e)this->emplace(e);} prique(const vector&a){fe(a,e)this->emplace(e);} friend T bg(prique&q){rr q.top();} friend T pot(prique&q){T r=q.top();q.pop();rr r;} friend os&operator<<(os&o,prique q){while(len(q))o<0,sp);rr o;} }; Iusing qmax=prique>; Iusing qmin=prique>; Istruct mset:multiset{ mset(const initializer_list&a={}){fe(a,e)this->emplace(e);} mset(const vector&a){fe(a,e)this->emplace(e);} friend os&operator<<(os&o,const mset&s){fe(s,e)o<struct set:mset{ set(const initializer_list&a={}){fe(a,e)this->emplace(e);} set(const vector&a){fe(a,e)this->emplace(e);} Iau emplace(A&&...a){ T x(std::forward(a)...); if(au p=this->find(x);p!=this->end())rr pair{p,0}; rr pair{this->mset::emplace(x),1}; } }; Istruct ve; Iconstexpr bo isv=0; Iconstexpr bo isv> =1; Iconstexpr bo isv> =1; Iau rawv(V){if constexpr(isv)rr rawv(V(1)[0]);else rr V();} Istruct ve:vector{ using vector::vector; using T=decltype(rawv(V())); Ive(const vector&v={}){static_assert(isv ==isv);fe(v,e)this->eb(e);} ve&operator+=(const ve&u){au&v=*this;fo(i,len(v))v[i]+=u[i];rr v;}ve operator+(const ve&u)const{rr ve(*this)+=u;} ve&operator-=(const ve&u){au&v=*this;fo(i,len(v))v[i]-=u[i];rr v;}ve operator-(const ve&u)const{rr ve(*this)-=u;} ve&operator^=(const ve&u){fe(u,e)this->eb(e);rr*this;}ve operator^(const ve&u)const{rr ve(*this)^=u;} ve&operator+=(const T&x){au&v=*this;fe(v,e)e+=x;rr v;}ve operator+(const T&x)const{rr ve(*this)+=x;} ve&operator-=(const T&x){au&v=*this;fe(v,e)e-=x;rr v;}ve operator-(const T&x)const{rr ve(*this)-=x;} ve&operator*=(const T&x){au&v=*this;fe(v,e)e*=x;rr v;}ve operator*(const T&x)const{rr ve(*this)*=x;} ve&operator++(){rr*this+=1;} ve&operator--(){rr*this-=1;} ve operator-()const{rr ve(*this)*=-1;} Iau&operator+=(const bset&a){fo(i,n)(*this)[i]+=a[i];rr*this;} Iau&operator-=(const bset&a){fo(i,n)(*this)[i]-=a[i];rr*this;} au lower_bound(const V&x)const{rr std::lower_bound(all(*this),x);} au upper_bound(const V&x)const{rr std::upper_bound(all(*this),x);} Iau scan(F f)const{cpr;fe(*this,e)if constexpr(!isv)r.b?f(r.a,e),r:r={e,1};else if(au s=e.scan(f);s.b)r.b?f(r.a,s.a),r:r=s;rr r;} T max()const{rr scan([](T&a,const T&b){ab?a=b:0;;}).a;} friend is&operator>>(is&i,ve&v){fe(v,e)i>>e;rr i;} friend os&operator<<(os&o,const ve&v){fe(v,e)o<?nl:sp);rr o;} }; Iau vec(const ll(&s)[n],T x={}){if constexpr(n==i+1)rr ve(s[i],x);else{au X=vec(s,x);rr ve(s[i],X);}} Ivo setsize(const ll(&l)[n],A&...a){((a=vec(l,rawv(a))),...);} Iusing v2=ve>;using u1=ve;using u2=v2; using graph=v2; vo io(){cin.tie(0)->sync_with_stdio(0);cout<vo li(A&...a){(cin>>...>>a);} Ivo vi(A&...a){fo(i,(len(a)&...))(cin>>...>>a[i]);} Ivo pp(const A&...a){ll i=sizeof...(a);((cout<0,c)),...);cout<u1 vsrt(F f,A&...a){u1 o=it((len(a)&...));sort(all(o),f);([&](au&e){au c=e;fo(i,len(e))e[i]=c[o[i]];}(a),...);rr o;} Istruct rec:F{rec(F&&f):F(std::forward(f)){}Idecltype(au)operator()(A&&...a)const{rr F::operator()(*this,std::forward(a)...);}}; namespace cht{ templatestruct line{ T a={},b={}; line(){} line(T a,T b):a(a),b(b){} bo operator<(const line&rhs)const{ return a!=rhs.a?a>rhs.a:bstruct crosspoint{ T n,d; linel; crosspoint(T n,T d,const line&l):n(n),d(d),l(l){ if(this->d<0)this->n*=-1,this->d*=-1; } bo operator<(const crosspoint&rhs)const{ return n*rhs.dcrosspointcalc_crosspoint(const line&l1,const line&l2){ return{l1.b-l2.b,l2.a-l1.a,l1}; } templatebo need(const line&l1,const line&l2,const line&l3){ if(l1.a==l2.a&&l1.b<=l2.b)return 0; return(l2.a-l1.a)*(l3.b-l2.b)<(l2.b-l1.b)*(l3.a-l2.a); } templatestruct min_convex_hull_trick{ set>ls; set>ps; vo add(T a,T b){ line l(a,b); auto lp=ls.emplace(a,b).first; if(lp!=ls.begin()&&lp!=prev(ls.end())){ if(need(*prev(lp),*lp,*next(lp))){ ps.erase(calc_crosspoint(*prev(lp),*next(lp))); }else{ ls.erase(lp); return; } } typename set>::iterator cu; if(lp!=ls.begin()){ cu=prev(lp); while(cu!=ls.begin()&&!need(*prev(cu),*cu,l)){ ps.erase(calc_crosspoint(*prev(cu),*cu)); cu=prev(cu); } ls.erase(next(cu),lp); lp=ls.find(l); ps.emplace(calc_crosspoint(*prev(lp),*lp)); } if(lp!=prev(ls.end())){ cu=next(lp); while(cu!=prev(ls.end())&&!need(l,*cu,*next(cu))){ ps.erase(calc_crosspoint(*cu,*next(cu))); cu=next(cu); } ls.erase(next(lp),cu); lp=ls.find(l); ps.emplace(calc_crosspoint(*lp,*next(lp))); } } T operator()(T x){ auto p=ps.lower_bound(crosspoint(x,1,line())); if(p!=ps.end())return p->l.a*x+p->l.b; else return ls.rbegin()->a*x+ls.rbegin()->b; } }; templatestruct max_convex_hull_trick:min_convex_hull_trick{ using base=min_convex_hull_trick; vo add(T a,T b){base::add(-a,-b);} T operator()(T x){return-base::operator()(x);} }; } vo main(){io();ll T=1;fo(T)solve();} templatell sgn(const T&a){return(a>=ee)-(a<=-ee);} templatell sgn(const T&a,const U&b){return sgn(a-b);} vo solve(){ LL(N); ve
a(N),b(N);vi(a,b); vsrt([&](ll i,ll j){rr sgn(b[i],b[j])?sgn(b[i],b[j])<0:sgn(a[i],a[j])<0;},a,b); cht::min_convex_hull_trick
cht_min; cht::max_convex_hull_trick
cht_max; fo(i,N)cht_min.add(-b[i],a[i]); of(i,N)cht_max.add(b[i],-a[i]); dd ans=0; dd t=0; fo(i,N){ if(b[i]){ amax(ans,zz(b[i]*cht_max(a[i]/b[i]))); amax(ans,zz(b[i]*cht_min(a[i]/b[i]))); }else{ amax(t,zz(a[i])); } } fo(i,N)b[i]=zz(b[i]); amax(ans,t*b.max()); pp(llroundl(ans)); }}