EID2 - Editorial

Now, whatā€™s wrong with this code??
I couldnā€™t find any test cases not working successfully !!!
Please help !
:sweat:

def eidi(l):
    if len(set(l[:3])) == len(set(l[3:])):
        F = l[:3]
        S = l[3:]
        for i in range(2):
            if F.index(min(F)) == S.index(min(S)):
                F.pop(F.index(min(F)))
                S.pop(S.index(min(S)))
                continue
            else:
                return "NOT FAIR"
        return "FAIR"
    else:
        return "NOT FAIR"

check = list()
for i in range(int(input())):
    l = list(map(int, input().split()))
    check.append(eidi(l))

print(*check, sep="\n")

Hereā€™s my solution in python:

for _ in range(int(input())):
    info = list(map(int, input().split()))
    ages = info[:3]
    money = info[3:]
    
    final = sorted(list(zip(ages,money)))
    final.sort(reverse=True)
    flag = True
    
    gp = final[0]
    for i in range(3):
        if final[i][0] < gp[0] and final[i][1] < gp[1]: gp = final[i]
        elif final[i][0] == gp[0] and final[i][1] == gp[1]: gp = final[i]
        else: flag = False
     
    if flag: print("FAIR")
    else: print("NOT FAIR")
import math

t = int(input())

for _ in range(t):
    a1, a2, a3, c1, c2, c3 = [int(x) for x in input().strip().split(" ")]
    if (a1 > a2 and c1 > c2) or (a1 == a2 and c1 == c2) or (a1 < a2 and c1 < c2):
        if (a1 > a3 and c1 > c3) or (a1 == a3 and c1 == c3) or (a1 < a3 and c1 < c3):
            if (a2 > a3 and c2 > c3) or (a2 == a3 and c2 == c3) or (a2 < a3 and c2 < c3):
                print ("FAIR")
            else:
                print ("NOT FAIR")
        else:
            print ("NOT FAIR")
    else:
        print ("NOT FAIR")

overkill solution
import java.util.;
import java.io.
;
import java.math.;
import java.util.regex.
;
import static java.lang.System.*;
CodeChef: Practical coding for everyone
public class Main{

static long start, stop, mod = (long) 1e9 + 7L;
static void debug(Object... a){
    err.println(Arrays.deepToString(a));
}
static void starttime(){start = currentTimeMillis();}
static void stoptime(){stop = currentTimeMillis();}
static void gettime(){err.println(((double)(stop - start) / 1000.0) + " seconds");}

static class FastReader{
    StringTokenizer st;
    BufferedReader br;
    FastReader(){
        br = new BufferedReader(new InputStreamReader(in));
    }
    String n(){
        while(st == null || !st.hasMoreElements()){
            try{
                st = new StringTokenizer(br.readLine());
            }
            catch(Exception e){
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int ni(){
        return Integer.parseInt(n());
    }
    float nf(){
        return Float.parseFloat(n());
    }

    double nd(){
        return Double.parseDouble(n());
    }
    long nl(){
        return Long.parseLong(n());
    }
    String ns(){
        String k="";
        try{
            k = br.readLine();
        }
        catch(Exception e){

            e.printStackTrace();
        }
        return k;

    }
}
static class pair<First extends Comparable<? super First>,
 Second extends Comparable<? super Second>> implements Comparable<pair<First, Second>>{
	public First first;
	public Second second;
	pair(First first,Second second){
		this.first = first;
		this.second = second;
	}
	public First getFirst(){
		return this.first;
	}
	public Second getSecond(){
		return this.second;
    }
    public void setFirst(First first){
        this.first = first;
    }
    public void setSecond(Second second){
        this.second = second;
    }
	@Override
	public String toString(){
		return  "[" + first + " " + second + "]";
    }
    @Override
    public int compareTo(pair<First, Second> pair){
        int res = this.first.compareTo(pair.first);
        return res == 0 ? this.second.compareTo(pair.second) : res; 
    }
	@Override
	public boolean equals(Object o){
		if(this == o)
			return true;
		if(o == null || getClass() != o.getClass())
			return false;
		pair<?,?> pair = (pair<?, ?>) o;
		if(!first.equals(pair.first)) return false;
		return second.equals(pair.second);
	}
	@Override
	public int hashCode(){
		return 31 * first.hashCode() + second.hashCode();
	}
}

public static void main(String args[]) throws IOException{
    FastReader in = new FastReader();
    	starttime();
        solve(in);
        stoptime();
        //gettime();
}
static void solve(FastReader in){
    int t = in.ni();
    while(t-- > 0){
        pair[] agesAndMoney = new pair[3];
        for(int i = 0; i < agesAndMoney.length; i++) agesAndMoney[i] = new pair<Integer, Integer>(in.ni(), 0);
        for(int i = 0; i < agesAndMoney.length; i++) agesAndMoney[i].setSecond(in.ni());
        Arrays.sort(agesAndMoney);
        int max = Integer.MIN_VALUE;
        String output = "FAIR";
        for(int i = 0; i < agesAndMoney.length - 1; i++){
            int first = agesAndMoney[i].getFirst().compareTo(agesAndMoney[i + 1].getFirst());
            int second = agesAndMoney[i].getSecond().compareTo(agesAndMoney[i + 1].getSecond());
            //System.out.println(first + " " + second);
            if((first == 0 && second != 0) ||
            (first < 0 && second >= 0) || 
            (first > 0 && second <= 0)){
                output = "NOT FAIR";
                break;
            }
        }
        System.out.println(output);
    }
}

}

Hi , this my code , and i really donā€™t know why its wrong ā€¦ Please help me out!!

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

class child
{
public:
    int age,money;
};

bool sortAge(child &a, child &b)
{
    return (a.age<b.age);
}
int main()
{
    int tc;
    cin>>tc;
    while(tc--)
    {
        vector<child>c;
        int arr[6];
        for(int i=0;i<6;i++)
            cin>>arr[i];
        for(int i=0;i<3;i++)
        {
            child j;
            j.age=arr[i];
            j.money=arr[i+3];
            c.push_back(j);
        }
        //c.sort(sortAge);
        sort(c.begin(),c.end(),sortAge);
        //for(int i=0;i<3;i++)
          //  cout<<c[i].age<<" "<<c[i].money<<endl;
        int flag=0;
        for(int i=0;i<2;i++)
        {
            if((c[i].age==c[i+1].age)&&(c[i].money!=c[i+1].money))
            {
                cout<<"NOT FAIR\n";
                flag=1;
                break;
            }
            else if(c[i].money > c[i+1].money)
            {
                cout<<"NOT FAIR\n";
                flag=1;
                break;
            }
        }
        if(flag==0)
            cout<<"FAIR\n";
        flag=0;
    }
}

Please format your code or link to a solution - this has been mangled by the forum software and is uncompilable. Thanks! :slight_smile:

Edit:

Thankyou - your code fails the following testcase:

1
12 4 6 29 24 29 

@rudransh_bt

Why this code is giving wrong answer

#include <iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<map>
#include<string>
#include<string.h>
#include<math.h>
#define REP(i, a, b)  for (int i = int(a); i <= int(b); i++)
#define NREP(i, a, b) for (int i = int(a); i >= int(b); i--)
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define circ_inc(i, n) (i + 1) % int(n)
#define circ_dec(i, n) (i + int(n) - 1) % int(n)
#define round(x) (int)((double)int(x) + 0.5)
#define println(x) cout << x << '\n'
#define F first
#define S second
#define INF 1000000000
#define gcd __gcd
#define nset __builtin_popcount
#define pb push_back
#define btoe(x) x.begin(), x.end()
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vector<int> > vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef map<string, int> msi;
typedef istringstream iss;

int main()
{
	FASTIO;
	int t;
	cin >> t;
	while (t--) {
		vi v1(4);//age array
		vi v2(4);//gift array4
		REP(i, 1, 3)
			cin >> v1[i];
		int v1_min = 0, v1_max = 0;
		v1_min = *min_element(v1.begin()+1, v1.end());
		v1_max = *max_element(v1.begin()+1, v1.end());




		REP(i, 1, 3) 
			cin >> v2[i];

		
		int v2_min = 0, v2_max = 0;
		v2_min = *min_element(v2.begin()+1, v2.end());
		v2_max = *max_element(v2.begin()+1, v2.end());


		int temp = 0;
		if (v1_min != v1_max) {
			REP(i, 1, 3) {

				if (v1[i] == v1_min && v2[i] == v2_min)
					temp++;
				else if (v1[i] == v1_max && v2[i] == v2_max)
					temp++;
				else if (v1[i] > v1_min && v1[i] < v1_max && v2[i] != v2_min && v1[i] != v2_max)
					temp++;

				


			}
			if (temp == 3)
				cout << "FAIR" << endl;
			else
				cout << "NOT FAIR" << endl;
		}
		else
		{
			if (std::adjacent_find(v2.begin() + 1, v2.end(), std::not_equal_to<>()) == v2.end())
			{
				cout << "FAIR" << endl;
			}
			else
				cout << "NOT FAIR" << endl;
		}
		
		
			
		

	}
	return 0;
}

Please format your code or link to a solution - this has been mangled by the forum software and is uncompilable. Thanks! :slight_smile:

1 Like

thanks . i did .
:slight_smile:

1 Like

Great :slight_smile: Your code also fails for the same testcase as @rudransh_btā€™s:

1
12 4 6 29 24 29 
1 Like

Thank you so much for replying . I will try to resolve the mistake in my code .

1 Like

@ssjgz just to clarify, i am getting output as FAIR for the test case you mentionedā€¦Is it not the correct output? Thankyou

No ā€œfairā€ is not the correct answer since age of first kid nd last kid are not same but both are getting equal cash.

1 Like

Ooh I get it now !!! Thanks a lot!!

Whats wrong in this code::

#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int T;
  cin >> T;
  while (T--) {
    int a1, a2, a3, c1, c2, c3;
    cin >> a1 >> a2 >> a3 >> c1 >> c2 >> c3;
    vector<pair<int, int>> vect;
    vect.push_back(make_pair(a1, c1));
    vect.push_back(make_pair(a2, c2));
    vect.push_back(make_pair(a3, c3));
    sort(vect.begin(), vect.end());

    string ans;
    for (int i = 0; i < 2; i++) {
      if (vect[i].first == vect[i + 1].first) {
        if (vect[i].second == vect[i + 1].second) {
          ans = "FAIR";
        } else {
          ans = "NOT FAIR";
          break;
        }
      } else if (vect[i].second < vect[i + 1].second) {
        ans = "FAIR";
      } else {
        ans = "NOT FAIR";
        break;
      }
    }
    std::cout << ans << '\n';
  }
  return 0;
}

It fails for the following testcase:

1
17 1 9 75 29 37 

@ssjgz Thanks for your quick reply. But I canā€™t figure out whatā€™s wrong here. it should be FAIR right??

Yes. Sorry, youā€™ve given me two bits of code and I donā€™t know which Iā€™m supposed to be looking at :slight_smile:

You gave the linked solution: CodeChef: Practical coding for everyone

and copy-n-pasted the solution:

#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int T;
  cin >> T;
  while (T--) {
    int a1, a2, a3, c1, c2, c3;
    cin >> a1 >> a2 >> a3 >> c1 >> c2 >> c3;
    vector<pair<int, int>> vect;
    vect.push_back(make_pair(a1, c1));
    vect.push_back(make_pair(a2, c2));
    vect.push_back(make_pair(a3, c3));
    sort(vect.begin(), vect.end());

    string ans;
    for (int i = 0; i < 2; i++) {
      if (vect[i].first == vect[i + 1].first) {
        if (vect[i].second == vect[i + 1].second) {
          ans = "FAIR";
        } else {
          ans = "NOT FAIR";
          break;
        }
      } else if (vect[i].second < vect[i + 1].second) {
        ans = "FAIR";
      } else {
        ans = "NOT FAIR";
        break;
      }
    }
    std::cout << ans << '\n';
  }
  return 0;
}

both of which are different. Which is the one you do want to be checked?

Edit:

Just seen your edit - the new code thatā€™s copy-n-pasted appears to work OK, for me - it passes 10ā€™000 randomised tests, at least!

Yes!!! Itā€™s AC when I replace read(T) with cin >> T

read(T) defined as follow::

template <class T> void read(T &x) {
  int f = 0;
  x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-')
      f = 1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = (x << 3) + (x << 1) + (s ^ 48);
    s = getchar();
  }
  x = f ? -x : x;
}

Isnā€™t read(T) equals cin >> T??:face_with_monocle:
Iā€™m not sure, whatā€™s the different here?? Can you please explain it?

Anyway, many many thanks for helping :heart:

Here is my solution to this problem it establish relation between two elements of an array and put the relationship in a third array and at last compares the relationship arrays
https://www.codechef.com/viewsolution/26177703