func_code_string: #include <bits/stdc++.h>   using namespace std;   const int maxn = 100050, maxm = 5050;   int n, m, K, p, h[maxn], a[maxn];   long long hh[maxn], ans;   long long tim[maxn];   int cnt[maxm];   bool judg(long long x) {     int i, j;     long long tis = 0;     for (i = 0; i < m; i++) cnt[i] = 0;     for (i = 0; i < n; i++) tis += tim[i] = max(0LL, (hh[i] - x - 1 + p) / p);     if (tis > K * m) return 0;     for (i = 0; i < n; i++) {       int now = 0, h0 = h[i];       for (j = 0; j < tim[i]; j++) {         long long t = h0 + 1LL * (m - now) * a[i] - 1LL * (tim[i] - j - 1) * p -                       x,                   tn;         if (h0 < t)           tn = now + (t - h0 - 1) / a[i] + 1;         else           tn = now;         if (tn >= m) return 0;         h0 = max(0LL, h0 + (tn - now) * a[i] - p);         cnt[now = tn]++;       }     }     for (i = m - 1; i >= 0; i--) {       cnt[i] += cnt[i + 1];       if (cnt[i] > (m - i) * K) return 0;     }     return 1;   }   int main() {     int i, j;     long long l = 0, r = 0, mid;     scanf( %d%d%d%d , &n, &m, &K, &p);     for (i = 0; i < n; i++)       scanf( %d%d , &h[i], &a[i]), r = max(r, hh[i] = h[i] + 1LL * a[i] * m);     while (l < r) {       mid = (l + r) >> 1;       if (judg(mid))         r = mid;       else         l = mid + 1;     }     ans = l;     printf( %I64d n , ans);     return 0;   }   