Preview:
#include <bits/stdc++.h>
using namespace std;


int main() {
     int n ;
     cin>>n;
     vector<pair<int , int> >p;
     for(int i=0;i<n;i++){
         int a, b ;
         cin>>a >>b ;
         int c=a+b;
         p.push_back({c,a});
         
         
        }
     reverse(p.begin(),p.end());
     
     int c=0;
     int ans=0;
     for(int i=0; i<n ;i++){
          c+=p[i].first;
          int sum=0;
         while(i+1<n){
             sum+=p[i+1].second;
             
             i++;
             
         }
         if(c>sum){
             ans=i+1;
             break; 
            }
         
         
         
        }
     
    cout<< ans;
   return 0; 
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter