#include using namespace std; typedef long long ll; #define FOR(I,A,B) for(int I = int(A); I < int(B); ++I) #define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I) const ll MOD=1000000007LL; #define out(a) cout<> N; vector> AB(N); FOR(i,0,N) cin >> AB[i].first; FOR(i,0,N) cin >> AB[i].second; sort(AB.begin(), AB.end()); ll f=0,X=AB[0].first; ll add = 0; FOR(i,1,N){ f += AB[i].second * (AB[i].first - X); add += -AB[i].second; } ll ansf = f, ansX = X; add += AB[0].second; FOR(i,1,N){ f += add * (AB[i].first - AB[i-1].first); if(f < ansf) { ansf = f; ansX = AB[i].first; } add += 2*AB[i].second; } cout << ansX << " " << ansf << endl; }