func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 500005;   int n, m, a[N], b[N];   priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,                  greater<pair<long long, long long> > >       Q;   long long ans;   int solve(int x) {     ans = 0;     int num = 0;     for (int i = (int)(1); i <= (int)(n); i++) {       Q.push(pair<long long, long long>(a[i], 0));       long long t = Q.top().first, now = b[i] - x;       if (now + t < 0) {         ans += now + t;         Q.pop();         Q.push(pair<long long, long long>(-now, 1));       }     }     for (; !Q.empty(); num += Q.top().second, Q.pop())       ;     return num;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = (int)(1); i <= (int)(n); i++) scanf( %d , &a[i]);     for (int i = (int)(1); i <= (int)(n); i++) scanf( %d , &b[i]);     long long l = 0, r = 2e9;     while (l <= r) {       long long mid = (l + r) / 2;       int sum = solve(mid);       if (sum == m) {         printf( %lld n , ans + 1ll * m * mid);         return 0;       }       if (sum < m)         l = mid + 1;       else         r = mid - 1;     }   }   