#include #include #define int long long using namespace std; int n; int a[200000]; int b[200000]; int bsum; int bsuml(int x) { int ret = 0; for (int i = 0; i < n; i++) { if (a[i] <= x) { ret += b[i]; } } return ret; } int f(int x) { int ret = 0; for (int i = 0; i < n; i++) { ret += b[i] * abs(a[i] - x); } return ret; } signed main() { int i; cin >> n; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n; i++) cin >> b[i]; for (i = 0; i < n; i++) bsum += b[i]; int ok = -1000001, ng = 1000001, mid; while (ng - ok >= 2) { mid = (ok + ng) / 2; if (bsuml(mid) * 2 <= bsum) ok = mid; else ng = mid; } cout << ok + 1 << " " << f(ok + 1) << endl; return 0; }