func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long int dx[] = {0, 1, -1, 0, 1, -1, -1, 1};   const long long int dy[] = {-1, 0, 0, 1, 1, 1, -1, -1};   long long int gcd(long long int x, long long int y) {     return (y != 0 ? gcd(y, x % y) : x);   }   long long int lcm(long long int x, long long int y) {     return (x / gcd(x, y) * y);   }   long long int limak;   long long int pos;   char matei[300010];   vector<pair<long long int, pair<long long int, long long int> > > v;   long long int n;   bool compare(pair<long long int, pair<long long int, long long int> > a,                pair<long long int, pair<long long int, long long int> > b) {     return a.second.first > b.second.first;   }   long long int solve() {     pos = 1;     memset(matei, 0, sizeof matei);     priority_queue<pair<long long int, long long int>,                    vector<pair<long long int, long long int> >,                    greater<pair<long long int, long long int> > >         pq;     int idx;     long long int melhorPos = 300000000;     for (idx = 0; idx < n; idx++) {       if (v[idx].second.first <= limak || v[idx].first == 0) break;       pq.push(make_pair(v[idx].second.second - v[idx].second.first + 1,                         v[idx].first));       matei[v[idx].first] = 1;       pos++;     }     melhorPos = pos;     long long int precisa, id;     while (!pq.empty()) {       precisa = pq.top().first;       id = pq.top().second;       pq.pop();       if (precisa > limak) break;       limak -= precisa;       pos--;       for (idx = idx; idx < n; idx++) {         if (v[idx].second.first <= limak) break;         if (!matei[v[idx].first] && v[idx].first != 0) {           pq.push(make_pair(v[idx].second.second - v[idx].second.first + 1,                             v[idx].first));           matei[v[idx].first] = 1;           pos++;         }       }       if (pos < melhorPos) melhorPos = pos;     }     return melhorPos;   }   int main() {     cin >> n;     long long int t, w;     for (int i = 0; i < n; i++) {       cin >> t >> w;       if (i == 0) limak = t;       v.push_back(make_pair(i, make_pair(t, w)));     }     sort(v.begin(), v.end(), compare);     cout << solve() << endl;     return 0;   }   