func_code_string: #include <bits/stdc++.h>   using namespace std;   pair<int, int> arr[1000006];   int main() {     int n, v, ans = 0, i, j, a, b, v1;     scanf( %d , &n);     scanf( %d , &v);     for (i = 0; i < n; ++i) {       scanf( %d , &a);       scanf( %d , &b);       arr[a].first += b;       arr[a + 1].second += b;     }     for (i = 0; i < 4; ++i)       cerr <<  i             <<  :   << i <<   |              <<  arr[i].F             <<  :   << arr[i].first <<   |              <<  arr[i].S             <<  :   << arr[i].second << endl;     ;     v1 = v;     for (i = 0; i < 3002; ++i) {       v1 = v;       if (i <= 3)         cerr <<  i               <<  :   << i <<   |                <<  arr[i].F               <<  :   << arr[i].first <<   |                <<  arr[i].S               <<  :   << arr[i].second <<   |                <<  v               <<  :   << v << endl;       ;       if (arr[i].second > 0) {         if (arr[i].second - v <= 0) {           v -= arr[i].second;           ans += arr[i].second;           arr[i].second = 0;         } else {           ans += v;           arr[i].second -= v;           v = 0;         }       }       if (i <= 3)         cerr <<  i               <<  :   << i <<   |                <<  arr[i].F               <<  :   << arr[i].first <<   |                <<  arr[i].S               <<  :   << arr[i].second <<   |                <<  v               <<  :   << v << endl;       ;       if (arr[i].first > 0) {         if (arr[i].first - v <= 0) {           ans += arr[i].first;           arr[i + 1].second -= arr[i].first;           arr[i].first = 0;           v -= arr[i].first;         } else {           cerr <<  i                 <<  :   << i << endl;           ;           ans += v;           arr[i].first -= v;           arr[i + 1].second -= v;           v = 0;         }       }       v = v1;       if (i <= 3)         cerr <<  i               <<  :   << i <<   |                <<  ans               <<  :   << ans << endl;       ;     }     printf( %d n , ans);     return 0;   }   