# Getting wrong answer in 9 testcases Atcoder abc187 question D(Choose me)

Atcoder round abc187 question D (Choose Me)

I am getting Wrong answer in this question(fail in 9 cases and passed in 22 cases)

with this code(C++) :-

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

#define ll long long
#define tej ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);

#define ve vector<int>
#define vl vector<long long int>
#define vp vector<pair<long long int,long long int>>
#define pb push_back
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define bp pop_back
#define fp pop_front
#define mp make_pair

#define fo(i,n) for(i=0;i<n;i++)
#define unq(v)      unique(v.begin(), v.end())-v.begin()
#define fnd(v,a)    find(v.begin(), v.end(), a)
#define uprb(v,a)   upper_bound(v.begin(), v.end(), a)
#define upra(v,n,a) upper_bound(v, v+n, a)
#define lowb(v,a)   lower_bound(v.begin(), v.end(), a)
#define lowa(v,n,a) lower_bound(v, v+n, a)
#define newuv(v)    v.erase(unique(v.begin(),v.end()),v.end())
#define rev(v)      reverse(v.begin(),v.end())
#define rndshf(v)   random_shuffle(v.begin(),v.end())
#define all(v)      v.begin(),v.end()

void solve()
{
ll n,s=0,i,co=0,s1=0,x,y;
cin>>n;
vl a,b,c;
vector<pair<ll,ll>>v;
fo(i,n)
{
cin>>x>>y;
a.pb(x);
b.pb(y);
s+=a[i];
c.pb(a[i]+b[i]);
v.pb(mp(c[i],a[i]));
}
sort(all(v));
for(i=n-1;i>=0;i--)
{
s1+=v[i].fi;
s-=v[i].se;
co++;
if(s1>s)
break;
}
cout<<co;
}

int main()
{
tej
ll t=1;
// cin>>t;
while(t--)
solve();
return 0;
}
``````

But I am getting an AC with this solution(C++):-

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

#define ll long long
#define tej ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);

#define ve vector<int>
#define vl vector<long long int>
#define vp vector<pair<long long int,long long int>>
#define pb push_back
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define bp pop_back
#define fp pop_front
#define mp make_pair

#define fo(i,n) for(i=0;i<n;i++)
#define unq(v)      unique(v.begin(), v.end())-v.begin()
#define fnd(v,a)    find(v.begin(), v.end(), a)
#define uprb(v,a)   upper_bound(v.begin(), v.end(), a)
#define upra(v,n,a) upper_bound(v, v+n, a)
#define lowb(v,a)   lower_bound(v.begin(), v.end(), a)
#define lowa(v,n,a) lower_bound(v, v+n, a)
#define newuv(v)    v.erase(unique(v.begin(),v.end()),v.end())
#define rev(v)      reverse(v.begin(),v.end())
#define rndshf(v)   random_shuffle(v.begin(),v.end())
#define all(v)      v.begin(),v.end()

void solve()
{
ll n,s=0,i,co=0,s1=0,x,y;
cin>>n;

vl v;
fo(i,n)
{
cin>>x>>y;
s-=x;
v.pb(2*x+y);
}
sort(all(v));
while(s<=0)
{
s+=v.back();
v.pop_back();
co++;
}
cout<<co;
}

int main()
{
tej
ll t=1;
// cin>>t;
while(t--)
solve();
return 0;
}

``````

I think both solutions are doing the same thing and have similar approach but still first one gives wrong ans.
Please tell me what is difference between this two solutions/Code/approach and what might be the test cases for which the previous one is getting wrong answer.