REMONE-START10C

According to que my logic seems to be ok. dont know why I’m getting WA at subtask 2

#include<bits/stdc++.h>
using namespace std;
int t;
int main()
{
cin>>t;
while(t–)
{
int i,n,k;
cin>>n;
int a[n],b[n-1];
for(i=0; i<n; i++)
{
cin>>a[i];
}

    for(i=0; i<n-1; i++)
    {
        cin>>b[i];
    }
    sort(a,a+n);
    sort(b,b+n-1);
    if(n==2)
    {
        if(b[0]-a[1]>0)
            cout<<b[0]-a[1];
        else
            cout<<b[0]-a[0];
    }

    else
    {
        if(b[0]-a[0]==b[n-2]-a[n-1])
            cout<<b[0]-a[0];
        else
        {
            if(b[0]-a[1]==b[n-2]-a[n-1])
                cout<<b[0]-a[1];
            else
                cout<<b[0]-a[0];
        }

    }
    cout<<endl;
}

}

case where b[0]-a[1]==b[n-2]-a[n-1] but its negative, so answer should have been b[0]-a[0], but you printed b[0]-a[1]

1 Like