func_code_string: #include <bits/stdc++.h>   using namespace std;   const int maxn = 100000 + 5;   const long long INF = 100000000000000;   long long h[maxn], p[maxn];   long long l[maxn], r[maxn];   int n, m;   bool ok(long long t) {     for (int i = 0; i < n; i++) {       l[i] = h[i];       r[i] = h[i];     }     int k = 0;     for (int i = 0; i < m; i++) {       if (p[i] >= l[k] && p[i] <= r[k]) continue;       if (p[i] < l[k]) {         if (r[k] - p[i] > t) {           return false;         } else {           l[k] = p[i];         }       }       if (p[i] > r[k]) {         if (p[i] - l[k] + min(p[i] - h[k], h[k] - l[k]) > t) {           k++;           if (k >= n) return false;           i--;         } else {           r[k] = p[i];         }       }     }     return true;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %I64d , &h[i]);     for (int i = 0; i < m; i++) scanf( %I64d , &p[i]);     long long l = -1, r = INF;     while (l < r - 1) {       long long mid = (l + r) / 2;       if (ok(mid)) {         r = mid;       } else {         l = mid;       }     }     cout << r << endl;   }   