#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 sum(K + 1); for(int i = 0; i < N; ++i) sum[mp[A[i]] + 1] += B[i]; for(int i = 0; i < K; ++i) sum[i + 1] += sum[i]; int X = 0; for(int i = 1; i <= K; ++i){ if(sum[i] * 2 >= sum[K]){ X = i - 1; break; } } 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'; }