class BIT: #0-indexed __slots__ = ["size", "tree","depth","n0"] def __init__(self, n): self.size = n self.tree = [0]*(n+1) self.depth = n.bit_length() self.n0 = 1< 0: s += self.tree[i] i -= i & -i return s def range_sum(self,l,r): #a_l + ... + a_r 閉区間 return self.get_sum(r) - self.get_sum(l-1) def range_sum_larger(self,l): #a_l + ... (端まで) return self.get_sum(self.size-1) - (self.get_sum(l-1) if l else 0) def add(self, i, x): i += 1 while i <= self.size: self.tree[i] += x i += i & -i def bisect_left(self,w): #和が w 以上になる最小の index #w が存在しない場合 self.size を返す #if w <= 0: return 0 x,k = 0,self.n0 for _ in range(self.depth): k >>= 1 if x+k <= self.size and self.tree[x+k] < w: w -= self.tree[x+k] x += k return x from bisect import bisect_left class AddAbsGetValOffline: def __init__(self,sa,za): self.sa = sa self.za = za n = len(sa) + 1 self.BIT_val = BIT(n) self.BIT_cnt = BIT(n) self.const = 0 self.val_all = 0 self.cnt_all = 0 def add_abs(self,pos,a,b): idx = self.za[pos] self.BIT_val.add(idx, (a+b)*pos) self.BIT_cnt.add(idx, a+b) self.val_all += a*pos self.cnt_all += a def add_const(self,x): self.const += x def getval(self, x, after_zaatu): if after_zaatu: x,zx = self.sa[x],x else: zx = bisect_left(self.sa,x) val = self.BIT_val.get_sum(zx-1) cnt = self.BIT_cnt.get_sum(zx-1) return self.val_all - val - x*(self.cnt_all - cnt) + self.const def getmin(self): idx = self.BIT_cnt.bisect_left(self.cnt_all) return sa[idx], self.getval(idx, True) ######################################################################## n = int(input()) *a, = map(int,input().split()) *b, = map(int,input().split()) sa = sorted(set(a)) za = {si:i for i,si in enumerate(sa)} data = AddAbsGetValOffline(sa,za) for ai,bi in zip(a,b): data.add_abs(ai,bi,bi) print(*data.getmin())