func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MAXARR = 2e5 + 5, MAXVAL = 1e6 + 5, MOD = 1e9 + 7, INF = 2147483647;   const long long INFLL = (1LL << 62);   int n, d, m;   int last[MAXARR];   pair<long long, long long> stop[MAXARR];   stack<pair<long long, long long> > st;   long long ans = 0LL;   template <class T>   void maximize(T &x, T y) {     if (x < y) x = y;   }   template <class T>   void minimize(T &x, T y) {     if (x > y) x = y;   }   bool get_bit(int i, int k) { return ((k >> (i - 1)) & 1); }   int change_bit(int i, int k) { return (k ^ (1 << (i - 1))); }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> d >> n >> m;     for (int i = 1; i <= m; i++) {       cin >> stop[i].first >> stop[i].second;     }     stop[++m] = pair<long long, long long>(0, 0);     stop[++m] = pair<long long, long long>(d, 0);     sort(stop + 1, stop + m + 1);     for (int i = 1; i <= m; i++) {       last[i] = INF;     }     for (int i = 1; i <= m; i++) {       while (!st.empty() && st.top().first > stop[i].second) {         last[st.top().second] = i;         st.pop();       }       st.push(pair<long long, long long>(stop[i].second, i));     }     long long now = n;     for (int i = 2; i <= m; i++) {       now -= stop[i].first - stop[i - 1].first;       if (now < 0) {         cout <<  -1 ;         exit(0);       }       if (last[i] != INF && stop[last[i]].first - stop[i].first <= n) {         ans += 1LL * max(0LL, (stop[last[i]].first - stop[i].first - now)) *                stop[i].second;         now = max(now, stop[last[i]].first - stop[i].first);       } else if (n + stop[i].first < d) {         ans += 1LL * (n - now) * stop[i].second;         now = n;       } else {         ans += 1LL * max(0LL, d - stop[i].first - now) * stop[i].second;         now = max(now, d - stop[i].first);       }     }     cout << ans;     return 0;   }   