func_code_string: #include <bits/stdc++.h>   int n, d, m, t[200005][2], l, p, r, b;   long long ans;   std::pair<int, int> s[200005];   bool a = true;   int main() {     scanf( %d %d %d , &d, &n, &m);     for (int i = 0; i < m; i++) scanf( %d %d , &s[i].first, &s[i].second);     std::sort(s, s + m);     t[l][0] = 0;     t[l++][1] = n;     s[m].first = d;     s[m].second = 0;     for (int i = 0; i <= m && a; i++) {       if (s[i].first - p > n)         a = false;       else {         r = s[i].first - p;         while (s[i].first > p) {           if (p + t[b][1] <= s[i].first) {             ans += (long long)t[b][0] * t[b][1];             p += t[b][1];             b++;           } else {             ans += (long long)t[b][0] * (s[i].first - p);             t[b][1] -= s[i].first - p;             p = s[i].first;           }         }         while (l > b && s[i].second <= t[l - 1][0]) r += t[--l][1];         t[l][0] = s[i].second;         t[l++][1] = r;       }     }     printf( %I64d n , a ? ans : -1);     scanf(  n );     return 0;   }   