func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 300005;   priority_queue<pair<long long, int> > Q;   int h[N], a[N];   int n, m, k, p;   bool check(long long lim) {     static long long now[N];     for (int i = 1; i <= n; i++) now[i] = lim;     while (!Q.empty()) Q.pop();     for (int i = 1; i <= n; i++)       if (now[i] - 1ll * a[i] * m < h[i]) Q.push(make_pair(-lim / a[i], i));     for (int i = 1; i <= m; i++)       for (int j = 1; j <= k; j++) {         if (Q.empty()) return true;         pair<long long, int> mx = Q.top();         Q.pop();         if (-mx.first < i) return false;         now[mx.second] += p;         if (now[mx.second] - 1ll * a[mx.second] * m < h[mx.second])           Q.push(make_pair(-now[mx.second] / a[mx.second], mx.second));       }     return Q.empty();   }   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]);     long long l = 0, r = 6e12, ans;     while (l <= r) {       long long mid = (l + r) >> 1ll;       if (check(mid))         ans = mid, r = mid - 1;       else         l = mid + 1;     }     printf( %lld , ans);     return 0;   }   