func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const int mod = 1e9 + 7;   const long long inf = 1e18;   int d, n, m, x[N], p[N], cur, r[N];   long long ans = inf, carry;   pair<int, int> a[N];   int main() {     ios_base::sync_with_stdio(0);     cin >> d >> n >> m;     for (int i = 1; i <= m; i++) cin >> a[i].first >> a[i].second;     vector<int> st;     sort(a + 1, a + m + 1);     for (int i = 1; i <= m; i++) x[i] = a[i].first, p[i] = a[i].second;     for (int i = m; i >= 0; i--) {       r[i] = i;       while (st.size() && p[st.back()] >= p[i]) {         r[i] = r[st.back()];         st.pop_back();       }       st.push_back(i);     }     for (int i = 0, j = 0; i <= m; i++) {       if (cur < 0) {         ans = inf;         break;       }       while (j + 1 <= m && x[j + 1] - x[i] <= n) j++;       if (n >= d - x[i]) {         long long dist = d - x[i];         long long cost = carry;         if (dist > cur) cost += 1ll * (dist - cur) * p[i];         ans = min(ans, cost);       }       if (j < r[i] + 1) {         carry += 1ll * (n - cur) * p[i];         cur = n;       } else {         long long dist = x[r[i] + 1] - x[i];         if (dist > n) dist = n;         if (dist > cur) {           carry += 1ll * (dist - cur) * p[i];           cur = dist;         }       }       cur -= (x[i + 1] - x[i]);     }     if (ans == inf) ans = -1;     cout << ans;     return 0;   }   