func_code_string: #include <bits/stdc++.h>   using namespace std;   int d, n, m;   const int M = 2e5;   pair<int, int> gas[M + 7];   bool possible = true;   int pendingD, running;   int currentGas;   long long res = 0;   struct cmp {     bool operator()(int c1, int c2) {       if (gas[c1].second != gas[c2].second)         return gas[c1].second > gas[c2].second;       else         return gas[c1].first < gas[c2].first;     }   };   priority_queue<int, vector<int>, cmp> heap;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> d >> n >> m;     int r1, r2;     for (int i = 1; i <= m; i++) {       cin >> r1 >> r2;       gas[i] = {r1, r2};     }     sort(gas + 1, gas + m + 1);     gas[0] = {0, 0};     gas[m + 1] = {d, 0};     for (int i = 1; i <= m + 1; i++)       if (gas[i].first - gas[i - 1].first > n) {         possible = false;         break;       }     if (!possible) {       cout << -1;       exit(0);     }     pendingD = 0;     running = 1;     currentGas = 0;     while (pendingD <= m) {       for (int i = running; i <= m + 1; i++)         if (gas[i].first - gas[pendingD].first > n) {           running = i;           break;         } else {           heap.push(i);           if (gas[i].second < gas[pendingD].second) {             running = i + 1;             break;           }         }       while (heap.top() <= pendingD) heap.pop();       if (gas[heap.top()].second <= gas[pendingD].second) {         res += 1LL * gas[pendingD].second *                (gas[heap.top()].first - gas[pendingD].first - currentGas);         currentGas = 0;       } else {         res += 1LL * gas[pendingD].second * (n - currentGas);         currentGas = n - (gas[heap.top()].first - gas[pendingD].first);       }       pendingD = heap.top();       heap.pop();       running = max(running, pendingD + 1);     }     cout << res;     return 0;   }   