/** * @FileName a.cpp * @Author kanpurin * @Created 2020.10.09 22:03:53 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; int main() { int n;cin >> n; vector> a(n); for (int i = 0; i < n; i++) { cin >> a[i].first; } for (int i = 0; i < n; i++) { cin >> a[i].second; } sort(a.begin(), a.end()); vector sum(n+1),sum_b(n+1); for (int i = 0; i < n; i++) { sum[i+1] = sum[i] + a[i].first * a[i].second; sum_b[i+1] = sum_b[i] + a[i].second; } int l = -1, r = n; while(r - l > 2) { int mid1 = (r + 2*l) / 3; int mid2 = (2*r + l) / 3; ll sum1 = -sum[mid1]+sum[n]-sum[mid1+1]+(sum_b[mid1]-sum_b[n]+sum_b[mid1+1])*a[mid1].first; ll sum2 = -sum[mid2]+sum[n]-sum[mid2+1]+(sum_b[mid2]-sum_b[n]+sum_b[mid2+1])*a[mid2].first; if (sum1 > sum2) { l = mid1; } else { r = mid2; } } int k = (l+r)/2; ll ans1 = 0; ll ans2 = 0; ll ans3 = 0; constexpr long long LLINF = 1e18 + 1; if (l != -1) for (int i = 0; i < n; i++) { ans1 += abs(a[i].first - a[l].first) * a[i].second; } else ans1 = LLINF; for (int i = 0; i < n; i++) { ans2 += abs(a[i].first - a[k].first) * a[i].second; } if (r != n) for (int i = 0; i < n; i++) { ans3 += abs(a[i].first - a[r].first) * a[i].second; } else ans3 = LLINF; if (l != -1 && min({ans1,ans2,ans3}) == ans1) { cout << a[l].first << " " << ans1 << endl; } else if (min({ans1,ans2,ans3}) == ans2) { cout << a[k].first << " " << ans2 << endl; } else { cout << a[r].first << " " << ans3 << endl; } return 0; }