func_code_string: #include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   bool chmin(T1 &a, T2 b) {     return b < a && (a = b, true);   }   template <class T1, class T2>   bool chmax(T1 &a, T2 b) {     return a < b && (a = b, true);   }   template <class T1, class T2>   void sortPair(vector<T1> &v1, vector<T2> &v2) {     vector<pair<T1, T2>> u(v1.size());     for (int i = 0; i < u.size(); i++) u[i] = make_pair(v1[i], v2[i]);     sort(u.begin(), u.end());     for (int i = 0; i < u.size(); i++) tie(v1[i], v2[i]) = u[i];   }   long long solve() {     long long d, n, m;     cin >> d >> n >> m;     vector<long long> x(m), p(m);     for (int i = 0; i < (m); i++) scanf( %lld %lld , &x[i], &p[i]);     x.insert(x.begin(), 0);     p.insert(p.begin(), 0);     x.push_back(d);     p.push_back(0);     m += 2;     sortPair(x, p);     vector<long long> next(m, -1);     stack<int> s;     for (int i = (m)-1; i >= 0; i--) {       while (!s.empty() && p[i] <= p[s.top()]) s.pop();       next[i] = s.empty() ? -1 : s.top();       s.push(i);     }     long long full = n;     long long ans = 0;     int i = 0;     while (i < m - 1) {       if (x[i + 1] - x[i] > full) return -1;       long long use, dist, ni;       if (x[next[i]] - x[i] > full) {         dist = x[i + 1] - x[i];         use = full - n;         ni = i + 1;       } else {         dist = x[next[i]] - x[i];         use = max(0ll, dist - n);         ni = next[i];       }       ans += use * p[i];       n += use - dist;       i = ni;     }     return ans;   }   int main() {     cout << solve() << endl;     return 0;   }   