func_code_string: #include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T abs(T t) {     return t < 0 ? -t : t;   }   const long long modn = 1000000007;   inline long long mod(long long x) { return x % modn; }   const int MAXN = 212345;   int n, m, k;   pair<long long, long long> s[MAXN];   long long d, v, V;   set<pair<long long, long long> > q;   void fail() {     puts( -1 );     exit(0);   }   int main() {     long long res = 0;     scanf( %lld %lld %d , &d, &v, &n);     V = v;     for (int a = 0; a < n; a++) scanf( %lld %lld , &s[a].first, &s[a].second);     sort(s, s + n);     s[n].first = d;     s[n].second = INT_MAX;     int i = 0, j = 0;     long long up = v;     while (i <= n && s[i].first <= v) {       q.insert(pair<long long, long long>(s[i].second, s[i].first));       i++;       ;     }     long long ult = 0;     while (j <= n) {       ;       v -= s[j].first - ult;       if (v < 0) {         ;         fail();       }       if (j == n) break;       pair<long long, long long> top = *q.begin();       swap(top.first, top.second);       while (i <= n && v < V && top == s[j]) {         ;         if (i <= n && v + s[i].first - up <= V) {           res += s[j].second * (s[i].first - up);           v += s[i].first - up;           up = s[i].first;           q.insert(pair<long long, long long>(s[i].second, s[i].first));           i++;         } else if (i <= n) {           res += s[j].second * (V - v);           up += V - v;           v = V;         }         top = *q.begin();         swap(top.first, top.second);       }       ult = s[j].first;       q.erase(pair<long long, long long>(s[j].second, s[j].first));       j++;     }     printf( %lld n , res);   }   