func_code_string: #include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool chkmin(T &a, const T &b) {     return a > b ? a = b, 1 : 0;   }   template <typename T>   inline bool chkmax(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   const int oo = 0x3f3f3f3f;   const long long OO = 0x3f3f3f3f3f3f3f3fLL;   const int maxn = 200000;   int d, V, n;   pair<int, int> a[maxn + 5];   long long dp[maxn + 5];   int Min[maxn + 5];   int main() {     memset(Min, -1, sizeof Min);     scanf( %d%d%d , &d, &V, &n);     for (int i = (0), _end_ = (n); i < _end_; ++i)       scanf( %d%d , &a[i].first, &a[i].second);     a[n++] = make_pair(0, 0);     a[n++] = make_pair(d, 0);     sort(a, a + n);     for (int i = (0), _end_ = (n - 1); i < _end_; ++i)       if (a[i].first + V < a[i + 1].first) {         printf( -1 n );         return 0;       }     long long ans = 0;     int lst = 0, cur = 0;     for (int i = (1), _end_ = (n); i < _end_; ++i) {       cur = a[i - 1].first;       while (a[lst].first + V < a[i].first) {         ans += (long long)(a[lst].first + V - cur) * a[lst].second;         cur = a[lst].first + V;         int best = -1;         for (int j = lst + 1; j <= n; j += j & -j)           if (best == -1 || (Min[j] != -1 && a[Min[j]].second < a[best].second))             best = Min[j];         lst = best;       }       ans += (long long)(a[i].first - cur) * a[lst].second;       cur = a[i].first;       if (a[i].second < a[lst].second) lst = i;       for (int j = i; j > 0; j -= j & -j)         if (Min[j] == -1 || a[Min[j]].second > a[i].second) Min[j] = i;     }     printf( %I64d n , ans);     return 0;   }   