#pragma GCC optimize("O3") //コンパイラ最適化用 // #define _GLIBCXX_DEBUG //配列に[]でアクセス時のエラー表示 #include //sort,二分探索,など #include //固定長bit集合 #include //assert(p)で,not pのときにエラー #include #include //実行時間計測 #include #include //pow,logなど #include //複素数 #include #include #include #include //sortのgreater #include //setprecision(浮動小数点の出力の誤差) #include // std::left, std::right #include //入出力 #include //集合演算(積集合,和集合,差集合など) #include #include //iota(整数列の生成),gcdとlcm,accumulate #include #include #include #include #include #include #include #include //pair #include using namespace std; typedef long long LL; typedef long double LD; #define ALL(x) x.begin(), x.end() const long long INF = 1e12; const int MOD = 1e9 + 7; // const int MOD=998244353; //略記 #define UMAP unordered_map #define USET unordered_set #define FF first #define SS second #define int long long #define LD long double #define PII pair #define PB push_back #define MP make_pair #define SZ(x) (int)((x).size()) #define VI vector #define VVI vector> #define VLL vector #define VVLL vector> #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define REPD(i, n) for (int i = (int)(n) - (int)1; i >= 0; i--) #define FOR(i, a, b) for (int i = a; i < (int)(b); i++) #define FORD(i, a, b) for (int i = (int)(b) - (int)1; i >= (int)a; i--) const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}; const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; int in() { int x; cin >> x; return x; } // https://qiita.com/Lily0727K/items/06cb1d6da8a436369eed#c%E3%81%A7%E3%81%AE%E5%AE%9F%E8%A3%85 void print() { cout << "\n"; } template void print(Head &&head, Tail &&... tail) { cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward(tail)...); } template void print(vector &vec) { for (auto &a : vec) { cout << a; if (&a != &vec.back()) cout << " "; } cout << "\n"; } template void print(set &set) { for (auto &a : set) { cout << a << " "; } cout << "\n"; } template void print(vector> &df) { for (auto &vec : df) { print(vec); } } long long power(long long x, long long n) { // O(logn) // https://algo-logic.info/calc-pow/#toc_id_1_2 long long ret = 1; while (n > 0) { if (n & 1) ret *= x; // n の最下位bitが 1 ならば x^(2^i) をかける x *= x; n >>= 1; // n を1bit 左にずらす } return ret; } long long comb(int n, int k) { vector> v(n + 1, vector(n + 1, 0)); for (int i = 0; i < SZ(v); i++) { v[i][0] = 1; v[i][i] = 1; } for (int k = 1; k < SZ(v); k++) { for (int j = 1; j < k; j++) { v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]); } } return v[n][k]; } void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; } template inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } __attribute__((constructor)) void faster_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int n; void solve(int x, vector &vals) { int ans = 0; REP(ni, n) { ans += vals[ni].SS * abs(x - vals[ni].FF); } print(x, ans); } signed main() { cin >> n; vector vals(n); VI A(n), B(n); REP(ni, n) { cin >> A[ni]; } REP(ni, n) { cin >> B[ni]; } REP(ni, n) { vals[ni] = MP(A[ni], B[ni]); } sort(ALL(vals)); // REP(ni, n) { print(vals[ni].FF, vals[ni].SS); } int sum = 0; REP(ni, n) { sum += vals[ni].SS; } int temp = 0; int x; REP(ni, n) { temp += vals[ni].SS; if (temp >= sum / 2) { x = vals[ni].FF; break; } } solve(x, vals); return 0; }