#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using P = pair; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; template inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector A(N), B(N); map mp; for(int i = 0; i < N; ++i){ cin >> A[i]; mp[A[i]] = -1; } for(int i = 0; i < N; ++i) cin >> B[i]; int K = 0; vector xs; for(auto& it : mp){ it.second = K++; xs.emplace_back(it.first); } vector lsum(K + 1), rsum(K + 1); for(int i = 0; i < N; ++i){ lsum[mp[A[i]] + 1] += B[i]; rsum[mp[A[i]]] += B[i]; } for(int i = 0; i < K; ++i) lsum[i + 1] += lsum[i]; for(int i = K; i > 0; --i) rsum[i - 1] += rsum[i]; int X = 0; ll min_gap = 1e+17; ll cnt = 0; for(int i = 0; i < K; ++i){ ll gap = abs(lsum[i] - rsum[i + 1]); if(chmin(min_gap, gap)) X = i; else if(min_gap == gap){ if(chmax(cnt, lsum[i + 1] - lsum[i])) X = i; } } X = xs[X]; ll ans = 0; for(int i = 0; i < N; ++i) ans += (ll)B[i] * abs(X - A[i]); cout << X << ' ' << ans << '\n'; }