https://www.codechef.com/LTIME75B/problems/EID2

QUESTION LINK: CodeChef: Practical coding for everyone

MY SOLUTION LINK: CodeChef: Practical coding for everyone

Can someone help here please. I have used the logic that if the two structure arrays one sorted by age and the other sorted by cost(eidi) , are element wise same, then the distribution should be fair else not. All given test cases gives correct output ,But where i am getting wrong on submission?

#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
#define tc int t ;cin>>t ;while(t–)
#define pb push_back
#define FOR(i,n) for(int i =0;i<n;i++)
#define Sort(v) sort(v.begin() ,v.end())
#define vi vector
int32_t main()
{
ios::sync_with_stdio(0) ;
cin.tie(0) ; cout.tie(0) ;
tc
{
vector<pair<int , int >> v(3) ;
FOR(i,3 )
cin>>v[i].first ;
FOR(i,3)
cin>>v[i].second ;
int flag =1 ;
sort(v.begin() , v.end()) ;
FOR(i,2)
{
if(v[i].first == v[i+1].first )
{
if(v[i].second != v[i+1].second)
flag = 0 ;
}
else if (v[i].first < v[i+1].first)
{
if(v[i].second >=v[i+1].second)
flag= 0 ;
}

}
if(flag)
  cout<<"FAIR"<<"\n" ;
else
    cout<<"NOT FAIR"<<"\n" ;

}

return 0 ;
}
indent preformatted text by 4 spaces
use vector pair instead

please see my question…

yes i am replying for same question

what mistake i am making in the code?

code in python3

T = int(input())
for _ in range(T):
F = []
A1, A2, A3, C1, C2, C3 = map(int,input().split())
if(A1 != A2 and A1 != A3 and A2 != A3):
D = {A1:C1, A2:C2, A3:C3 }
for i in sorted (D):
F.append(D[i])
if(C1 != C2 and C1 != C3 and C2 != C3):
if(F == sorted(F)):
print(“FAIR”)
else:
print(“NOT FAIR”)
else:
print(“NOT FAIR”)
elif( A1 == A2 and A1 == A3):
if(C1 == C2 and C1 == C3):
print(“FAIR”)
else:
print(“NOT FAIR”)
else:
if(A1 == A2):
if(C1 == C2 and A1<A3 and C1<C3) or (C1 == C2 and A1>A3 and C1>C3):
print(“FAIR”)
else:
print(“NOT FAIR”)
if(A1 == A3):
if(C1 == C3 and A1<A2 and C1<C2) or (C1 == C3 and A1>A2 and C1>C2):
print(“FAIR”)
else:
print(“NOT FAIR”)
if(A3 == A2):
if(C3 == C2 and A1<A3 and C1<C3) or (C3 == C2 and A1>A3 and C1>C3):
print(“FAIR”)
else:
print(“NOT FAIR”)

I can explain you my code if u need.

can someone please look into my code and tell where i am going wrong…( I can go for successful submissions for the correct solutions if i had to)

sorting is done separately so can not predict actual cost assign to the age initially
Eg. Age - 5 1 4
cost - 3 4 5
after sorting separately actual indexing can not be predicted

I am doing the structure sort…the age and cost of every child are as a single element of that structure array…please look

Bro, you are sorting the array differently so the index order will not be known.
I went through your code.

Please put these lines in your code to debug , print after sorting both the array and you can see the difference.

sort(arr2,arr2+3,compare);
sort(arr3,arr3+3,compare2);

   cout<<"-----------------"<<endl;
   for(int i=0;i<3;i++){
       cout<<arr2[i].age<< " " <<arr2[i].cost<<endl;
   }
   cout<<"*************"<<endl;
   for(int i=0;i<3;i++){
       cout<<arr3[i].age<< " " <<arr3[i].cost<<endl;
   }
   cout<<"*************"<<endl;

Also use the below test case to see the difference.
INPUT
2
5 5 5 20 20 10
5 5 5 20 10 20

OUTPUT

5 20
5 20
5 10


5 20
5 20
5 10


FAIR

5 20
5 10
5 20


5 20
5 20
5 10


NOT FAIR

Means you last logic to sort and decide “FAIR” and “NOT FAIR” is not in sync.

Happy to Help 3000. :wink:

1 Like