#include #include #include using namespace std; using ll = long long; int main() { ll N; vector A(200000), B(200000); ll B_sum = 0; ll Med; ll flag = 1, count = 0; ll argx = 0, fx = 0; vector> P(200000,make_pair(0,0)); cin >> N; for (int i = 0; i < N; i++) { cin >> A.at(i); } for (int i = 0; i < N; i++) { cin >> B.at(i); B_sum += B.at(i); } Med = (B_sum + 1) / 2; for (int i = 0; i < N; i++) { P.at(i) = make_pair(A.at(i), B.at(i)); } sort(P.begin(), P.end()); for (int i = 0; i < P.size(); i++) { count += P.at(i).second; if ((flag == 1) && count >= Med) { flag = 0; argx = P.at(i).first; } } for (int i = 0; i < P.size(); i++) { fx += P.at(i).second * abs(argx - P.at(i).first); } cout << argx << " " << fx << endl; }