func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 6;   int n, k, h[N];   long long p, m, t, a[N], b[N];   struct xd {     int z, i;     bool operator<(const xd &d) const { return z > d.z; }   } tmp, nw;   inline int read() {     int T = 0, F = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) F = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       T = (T << 3) + (T << 1) + (ch - 48), ch = getchar();     return F * T;   }   bool check(long long x) {     priority_queue<xd> q;     memset(b, 0, sizeof(b));     for (int i = 1; i <= n; ++i)       if (x - a[i] * m < h[i]) tmp.z = x / a[i], tmp.i = i, q.push(tmp);     for (int i = 1; i <= m && !q.empty(); ++i)       for (int j = 1; j <= k && !q.empty(); ++j) {         tmp = q.top(), q.pop();         if (tmp.z < i) return 0;         ++b[tmp.i];         if (x + b[tmp.i] * p - a[tmp.i] * m < h[tmp.i])           tmp.z = (x + b[tmp.i] * p) / a[tmp.i], q.push(tmp);       }     return q.empty();   }   long long ef(long long l, long long r) {     if (l == r) return l;     long long mid = l + r >> 1ll;     if (check(mid)) return ef(l, mid);     return ef(mid + 1, r);   }   int main() {     n = read(), m = read(), k = read(), p = read();     for (int i = 1; i <= n; ++i) h[i] = read(), a[i] = read();     printf( %lld n , ef(0, 5e12 + 1e9 + 1));     return 0;   }   