func_code_string: #include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5, oo = 0x3f3f3f3f;   pair<int, int> stop[maxn];   int nxt[maxn];   int main(void) {     int d, n, m;     scanf( %d%d%d , &d, &n, &m);     int x, y;     for (int i = 1; i <= m; i++) {       scanf( %d%d , &x, &y);       stop[i] = pair<int, int>(x, y);     }     stop[0] = pair<int, int>(0, 0);     stop[m + 1] = pair<int, int>(d, 0);     sort(stop, stop + m + 1);     stack<int> s;     memset(nxt, -1, sizeof(nxt));     for (int i = m; i >= 1; i--) {       while (!s.empty() && stop[i].second <= stop[s.top()].second) s.pop();       if (s.empty())         nxt[i] = m + 1;       else         nxt[i] = s.top();       s.push(i);     }     nxt[0] = s.top();     int after;     long long ans = 0;     int now = n;     int dist;     for (int i = 0; i <= m + 1; i++) {       if (now < 0) return puts( -1 ), 0;       dist = stop[nxt[i]].first - stop[i].first;       if (dist > now)         after = dist;       else         after = now;       if (after > n) after = n;       ans += (after - now) * 1ll * stop[i].second;       after -= stop[i + 1].first - stop[i].first;       now = after;     }     printf( %I64d n , ans);     return 0;   }   