func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MAXN = 200005;   const int INFTY = 1 << 30;   int D, N, M;   pair<int, int> pos[MAXN];   vector<int> S;   int nxt[MAXN];   int main() {     scanf( %d %d %d , &D, &N, &M);     for (int i = 0; i < M; i++) scanf( %d %d , &pos[i].first, &pos[i].second);     sort(pos, pos + M);     pos[M] = make_pair(D, 0);     for (int i = M - 1; i >= 0; i--) {       while (!S.empty() && pos[S.back()].second > pos[i].second) S.pop_back();       nxt[i] = S.empty() ? M : S.back();       S.push_back(i);     }     long long ans = 0;     int cur = N - pos[0].first;     for (int i = 0; i < M; i++) {       if (cur < 0) {         printf( -1 n );         return 0;       }       int need = min(N, pos[nxt[i]].first - pos[i].first);       int add = max(0, need - cur);       ans += (long long)pos[i].second * add;       cur += add - (pos[i + 1].first - pos[i].first);     }     if (cur < 0)       printf( -1 n );     else       printf( %I64d n , ans);     return 0;   }   