#include using namespace std; #define ll long long #define rep(i, n) for (int i = 0; i < (n); i++) #define P pair int main() { int N; cin >> N; vector a(N), b(N); vector

vec(N); ll sum = 0; rep(i, N) cin >> a[i]; rep(i, N) { cin >> b[i]; sum += b[i]; vec[i] = {a[i], b[i]}; } sort(vec.begin(), vec.end()); ll subsum = 0; ll x; rep(i, N) { subsum += vec[i].second; // subsum が sum - subsum 以上になる瞬間 x = A[i] が答え. if (subsum * 2 >= sum) { x = vec[i].first; break; } } cout << x << " "; // f(x)の値 ll ans = 0; rep(i, N) { if (vec[i].first < x) { ans += vec[i].second * (x - vec[i].first); } else { ans -= vec[i].second * (x - vec[i].first); } } cout << ans << endl; }