Snippets Collections
#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; 
}
star

Mon Jun 20 2022 10:05:00 GMT+0000 (Coordinated Universal Time) https://www.codechef.com/ide?itm_medium

#disctionary #sorting

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension