func_code_string: #include <bits/stdc++.h>   const int MAXN = 1e5 + 10;   int n, m, k, p;   int h[MAXN], a[MAXN];   namespace solver1 {   long long fin[MAXN];   bool check(long long x) {     long long need = 0;     static long long t[MAXN];     for (int i = 1; i <= n; i++) {       need += (t[i] = std::max(0ll, (fin[i] - x + p - 1) / p));     }     if (need > k * m) return 0;     static int cnt[MAXN];     memset(cnt, 0, sizeof cnt);     for (int i = 1; i <= n; i++) {       for (int j = t[i] - 1; j >= 0; j--) {         long long delta = fin[i] - x - (long long)j * p;         if (delta <= h[i]) {           cnt[1]++;         } else if (h[i] + (long long)a[i] * (m - 1) < delta) {           return 0;         } else {           cnt[(delta - h[i] + a[i] - 1) / a[i] + 1]++;         }       }     }     int tot = 0;     for (int i = 1; i <= m; i++) {       tot += cnt[i];       tot = std::max(0, tot - k);     }     return tot == 0;   }   void main() {     for (int i = 1; i <= n; i++) {       fin[i] = (long long)a[i] * m + h[i];     }     long long l = 1, r = 1e15, ans = 1e15;     while (l <= r) {       long long mid = (l + r) >> 1;       if (check(mid)) {         ans = mid;         r = mid - 1;       } else {         l = mid + 1;       }     }     printf( %lld n , ans);   }   }  // namespace solver1   int main() {     scanf( %d%d%d%d , &n, &m, &k, &p);     for (int i = 1; i <= n; i++) {       scanf( %d%d , h + i, a + i);     }     solver1::main();   }   