func_code_string: #include <bits/stdc++.h>   using namespace std;   long long int d[200060], cost[200060];   long long int m, tank;   vector<pair<int, int>> temp;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int src;     cin >> src >> tank >> m;     d[0] = 0;     cost[0] = 0;     d[m + 1] = src;     cost[m + 1] = 0;     for (int i = 0; i < m; i++) {       pair<int, int> t;       cin >> t.first >> t.second;       temp.push_back(t);     }     sort(temp.begin(), temp.end());     for (int i = 0; i < m; i++) {       d[i + 1] = temp[i].first;       cost[i + 1] = temp[i].second;     }     int current = 0;     long long int fuel = tank;     int toAdd = 1;     auto srt = [](int i, int j) {       pair<int, int> a = make_pair(cost[i], d[i]);       pair<int, int> b = make_pair(cost[j], d[j]);       return a < b;     };     multiset<int, function<bool(int, int)>> stations(srt);     long long int ans = 0;     while (true) {       while (!stations.empty() && d[*stations.begin()] < d[current]) {         stations.erase(stations.begin());       }       while (toAdd <= m + 1 && (d[current] + tank) >= d[toAdd]) {         stations.insert(toAdd);         toAdd++;       }       auto it = stations.begin();       if (it == stations.end()) {         cout << -1;         return 0;       }       int minPricy = *it;       if (cost[minPricy] >= cost[current]) {         long long int fuelNeeded = d[minPricy] - d[current];         ans += max(0ll, (tank - fuel) * cost[current]);         fuel = tank - fuelNeeded;         current = minPricy;         stations.erase(it);       } else {         int check = current + 1;         while (cost[current] <= cost[check]) {           check++;         }         int minPricy = check;         long long int fuelNeeded = d[minPricy] - d[current];         ans += max(0ll, (fuelNeeded - fuel) * cost[current]);         fuel = max(fuel - fuelNeeded, 0ll);         current = minPricy;       }       if (current == m + 1) break;     }     cout << ans;     return 0;   }   