EID2 - Editorial

It doesnt work for this test case.
1
7 7 4 8 8 8

can anyone please help me out.
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t–)
{
int a[6],i,m=INT_MAX,j,z=0;
for(i=0;i<6;i++) cin >> a[i];
for(i=0;i<3;i++)
if(a[i]<m) {m=a[i]; j=i;}
swap(a[0],a[j]); swap(a[3],a[j+3]);
if(a[1]>a[2])
{swap(a[1],a[2]); swap(a[4],a[5]);}
for(i=1;i<3;i++)
{
if(a[i]==a[i-1] && a[i+3]!=a[i+2]) z=1;
else if(a[i+3]<=a[i+2]) z=1;
}
if(z==1) cout<<ā€œNOT FAIRā€<<endl;
else cout<<ā€œFAIRā€<<endl;
}
return 0;
}

Please format your code, or link to a solution - the forum software has mangled your code and it won’t compile!

Consider the testcase:

1
2 11 11 38 73 73 

#include<iostream>
using namespace std;

int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		int A[3],C[3];
		for(int i=0;i<3;i++)
		{
			cin>>A[i];
		}
		for(int i=0;i<3;i++)
		{
			cin>>C[i];
		}
		for(int i = 1,j,key1,key2;i<3;i++)
		{
			j = i-1;
			key1 = A[i];
			key2 = C[i];
			while(j >= 0 && key1 < A[j])
			{
				A[j+1]=A[j];
				C[j+1] = C[j];
				j--;
			}
			A[j+1] = key1;
			C[j+1] = key2;
		}
		bool deal = true;
		for(int i = 1;i<3;i++)
		{
			if(A[i]==A[i-1])
			{
				if(C[i]!=C[i-1])
				{
					deal = false;
					break;
				}
			}
			if(C[i-1] > C[i])
			{
				deal = false;
				break;
			}
		}
		if(deal)
		{
			cout<<"FAIR"<<endl;
		}
		else
		{
			cout<<"NOT FAIR"<<endl;
		}
	}
	return 0;
}

I have sorted the age list/array and arranged the corresponding cost list/array, and then checked the fairness.

where I’m doing mistake that I’m resulting into a WA.

Thanks for formatting your code :slight_smile:

It fails on the following testcase:

1
12 4 6 29 24 29 
1 Like

I was doing such a silly mistake…
thanks for the help buddy.

1 Like

When you know what Integer.compare(int a, int b) does…

static String isFair(int[] age, int[] amount) {
	if((Integer.compare(age[0], age[1]) != 
				Integer.compare(amount[0], amount[1]))
			|| (Integer.compare(age[1], age[2])) !=
				Integer.compare(amount[1], amount[2])
			|| (Integer.compare(age[0], age[2])) !=
				Integer.compare(amount[0], amount[2]))
		return "NOT FAIR";
	
	return "FAIR";
}

import java.util.*;
class EID2 {

public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	int t=sc.nextInt();
	while(t!=0)
	{
		int []a=new int[6];
		int temp=0;
		int d=0;
		int i1=0,i2=0,i3=0,i4=0;
		for(int i=0;i<6;i++)
		{
			a[i]=sc.nextInt();
		}
		int temp1[]=new int[3];
		int temp2[]=new int[3];
		for(int i=0;i<3;i++)
		{
			temp1[i]=a[i];
		}
		
		System.out.println();
		int j=0;
		for(int i=3;i<6;i++)
		{	
			temp=a[i];
			temp2[j]=temp;
			j++;
		}
		
		if(temp1[0]==temp1[1] && temp1[1]==temp1[2])
		{
			if(temp2[0]!=temp2[1] && temp2[1]!=temp2[2])
			{
				d=2;
			}
		}
		else
		if(temp1[0]==temp1[1])
		{
			if(temp2[0]!=temp2[1])
			{
				d=2;
			}
			
		}
		else
			if(temp1[1]==temp1[2])
			{
				if(temp2[1]!=temp2[2])
				{
					d=2;
				}
			}
			else
				if(temp1[0]==temp1[2])
				{
					if(temp2[0]!=temp2[2])
					{
						d=2;
					}
				}
				else
				{
					int smallest = temp1[0];
			        int biggest = temp1[0];
					for(int i=1; i< temp1.length; i++)
			        {
			                if(temp1[i] > biggest)
			                {
			                        biggest = temp1[i];
			                		i1=i;
			                }
			                else if (temp1[i] < smallest)
			                {
			                        smallest = temp1[i];
			                        i2=i;
			                }
			               
			        }
					int small = temp2[0];
			        int big = temp2[0];
					for(int i=1; i< temp2.length; i++)
			        {
			                if(temp2[i] > big)
			                {
			                        big = temp2[i];
			                        i3=i;
			                }
			                else if (temp2[i] < small)
			                {
			                        small = temp2[i];
			                        i4=i;
			                }
			               
			        }
					d=1;
				}
		if(d==2)
		{
			System.out.print("NOT FAIR"); 
		}
		else
			if(d==0)
			{
				int smallest = temp1[0];
		        int biggest = temp1[0];
				for(int i=1; i< temp1.length; i++)
		        {
		                if(temp1[i] > biggest)
		                {
		                        biggest = temp1[i];
		                		i1=i;
		                }
		                else if (temp1[i] < smallest)
		                {
		                        smallest = temp1[i];
		                        i2=i;
		                }
		               
		        }
				int small = temp2[0];
		        int big = temp2[0];
				for(int i=1; i< temp2.length; i++)
		        {
		                if(temp2[i] > big)
		                {
		                        big = temp2[i];
		                        i3=i;
		                }
		                else if (temp2[i] < small)
		                {
		                        small = temp2[i];
		                        i4=i;
		                }
		               
		        }
				if(i1==i3 && i2==i4) {
					System.out.print("FAIR");
				}
				else {
					System.out.print("NOT FAIR");
				}
			}
			else
				if(d==1) {
					if(i1==i3 && i2==i4) {
						System.out.print("FAIR");
					}
					else {
						System.out.print("NOT FAIR");
					}
				}
		//	System.out.println();
		t--;
	}
}

}

please help me, why it is giving me wrong answer. Atleast tell me, which test cases is not satisfy

  1. Your solution always prints an empty line before all the other outputs :slight_smile:
  2. Consider the testcase:
1
12 4 6 29 24 29 
1 Like

thanks buddy… :v:

1 Like

import java.util.*;
class EID2 {

public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	int t=sc.nextInt();
	while(t!=0)
	{
		int []a=new int[6];
		int temp=0;
		int d=0;
		int i1=0,i2=0,i3=0,i4=0;
		for(int i=0;i<6;i++)
		{
			a[i]=sc.nextInt();
		}
		
		int temp1[]=new int[3];
		int temp2[]=new int[3];
		for(int i=0;i<3;i++)
		{
			temp1[i]=a[i];
		}
		int j=0;
		for(int i=3;i<6;i++)
		{	
			temp=a[i];
			temp2[j]=temp;
			j++;
		}
		
			for(int i=0;i<2;i++)
			{
				if(temp1[i]==temp1[i+1])
				{
					if(temp2[i]!=temp2[i+1])
					{
						d=2;
					}
				}
			}
			for(int i=0;i<2;i++)
			{
				if(temp2[i]==temp2[i+1])
				{
					if(temp1[i]!=temp1[i+1])
					{
						d=2;
					}
				}
			}
				if(temp1[0]==temp1[2])
				{
					if(temp2[0]!=temp2[2])
					{
						d=2;
					}
				}
				else
					if(temp2[0]==temp2[2])
					{
						if(temp1[0]!=temp1[2])
						{
							d=2;
						}
					}
				else
				{
					int smallest = temp1[0];
			        int biggest = temp1[0];
					for(int i=1; i< temp1.length; i++)
			        {
			                if(temp1[i] > biggest)
			                {
			                        biggest = temp1[i];
			                		i1=i;
			                }
			                else if (temp1[i] < smallest)
			                {
			                        smallest = temp1[i];
			                        i2=i;
			                }
			               
			        }
					int small = temp2[0];
			        int big = temp2[0];
					for(int i=1; i< temp2.length; i++)
			        {
			                if(temp2[i] > big)
			                {
			                        big = temp2[i];
			                        i3=i;
			                }
			                else if (temp2[i] < small)
			                {
			                        small = temp2[i];
			                        i4=i;
			                }
			               
			        }
					d=1;
				}
		if(d==2)
		{
			System.out.print("NOT FAIR"); 
		}
		else
			if(d==0)
			{
				int smallest = temp1[0];
		        int biggest = temp1[0];
				for(int i=1; i< temp1.length; i++)
		        {
		                if(temp1[i] > biggest)
		                {
		                        biggest = temp1[i];
		                		i1=i;
		                }
		                else if (temp1[i] < smallest)
		                {
		                        smallest = temp1[i];
		                        i2=i;
		                }
		               
		        }
				int small = temp2[0];
		        int big = temp2[0];
				for(int i=1; i< temp2.length; i++)
		        {
		                if(temp2[i] > big)
		                {
		                        big = temp2[i];
		                        i3=i;
		                }
		                else if (temp2[i] < small)
		                {
		                        small = temp2[i];
		                        i4=i;
		                }
		               
		        }
				if(i1==i3 && i2==i4) {
					System.out.print("FAIR");
				}
				else {
					System.out.print("NOT FAIR");
				}
			}
			else
				if(d==1) {
					if(i1==i3 && i2==i4) {
						System.out.print("FAIR");
					}
					else {
						System.out.print("NOT FAIR");
					}
				}
			System.out.println();
		    t--;
	}	
}

}

still not getting after improvement… can you help?

1
17 17 8 63 17 11 
1 Like

Love you Man :smiling_face_with_three_hearts:…thanks for helping me… I never thought this could finally be submit by me.

1 Like