func_code_string: #include <bits/stdc++.h>   using namespace std;   pair<int, int> stations[200001];   int nxt[200001];   int main() {     int d, n, m;     scanf( %d%d%d , &d, &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d%d , &stations[i].first, &stations[i].second);     }     sort(stations, stations + m);     stack<int> s;     for (int i = m - 1; i > -1; i--) {       nxt[i] = -1;       while (!s.empty()) {         if (stations[s.top()].second > stations[i].second) {           s.pop();         } else {           nxt[i] = s.top();           break;         }       }       s.push(i);     }     long long cost = 0;     int gas = n;     for (int i = 0; i < m; i++) {       gas -= stations[i].first - (i == 0 ? 0 : stations[i - 1].first);       if (gas < 0) {         cout << -1 << endl;         return 0;       }       int needed;       if (nxt[i] == -1 || stations[nxt[i]].first - stations[i].first > n) {         needed = min(n, d - stations[i].first);       } else {         needed = stations[nxt[i]].first - stations[i].first;       }       if (gas < needed) {         cost += (long long)stations[i].second * (needed - gas);         gas = needed;       }     }     gas -= d - stations[m - 1].first;     if (gas < 0) {       cout << -1 << endl;     } else {       cout << cost << endl;     }   }   