#include #include #include #include using namespace std; typedef long long ll; typedef pair pii; int main(){ int n; cin >> n; int a[n], b[n]; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < n; i++) cin >> b[i]; vector vp; for(int i = 0; i < n; i++) vp.push_back({a[i], b[i]}); sort(vp.begin(), vp.end()); ll sum = accumulate(b, b+n, 0ll); ll acc = 0, piv; for(int i = 0; i < n; i++){ acc += vp[i].second; if(acc >= (sum+1)/2){ piv = vp[i].first; break; } } ll ans = 0; for(int i = 0; i < n; i++){ ans += (ll)b[i] * abs(piv-a[i]); } cout << piv << " " << ans << endl; return 0; }