VALIDMIN-EDITORIAL

PROBLEM LINK:

Contest
Practice

Setter: abhi_inav
Testers: iceknight1093 , jeevanjyot
Editorialist: kiran8268

DIFFICULTY:

1132

PREREQUISITES:

None

PROBLEM:

There are 3 hidden numbers A, B , C
Given the values of min(A, B), min(B, C), min(C,A). Determine whether there exists any tuple (A, B, C) that satisfies the given values of min(A, B), min(B, C), min(C, A).

EXPLANATION:

Read the inputs to an array and sort them.
Let the sorted elements be a[0], a[1] and a[2].
If a[0]=a[1] , output YES else NO.

TIME COMPLEXITY:

Time complexity is O(1).

SOLUTION:

Editorialist's Solution
int t;
	cin >> t;
	while(t--)
	{
	    int a[3];
	    for(int i=0;i<3;i++)
	    {
	        cin>>a[i];
	    }
	    
	    sort(a, a + 3);
	    if(a[0] == a[1])
	    cout << "YES"<<"\n";
	    
	    else cout << "NO"<<"\n";
	    
	}
1 Like

In Explanation section it is given in test case 3 that “One valid tuple (A,B,C) is (4,2,5).”
but using editorialist’s solution we get NO as an answer why?

Hello friend, actually a[0]=min(A,B) , a[1]=min(B,C) and a[2]=min(C,A) and tuple (A,B,C)=(4,2,5) satisfies this as min(4,2)=2=a[0], min(2,5)=2=a[1] and therefore a[0]=a[1]. Hence the answer should be YES. Hope you have understood :slight_smile:

2 Likes

could you please, explain why do we need to sort
my approach: as it was minimum and going circularly , there will be two or more elements which are always same. if a[0]==a[1] or a[1]==a[2] or a[2]==a[0] , then it is a valid tuple.
please correct me if i am wrong

4 Likes

if a[0]==a[1] or a[1]==a[2] or a[2]==a[0]
why was this failing in submission as it was same

Not only any two elements must be equal ,but the remaining element must be greater than or equal to these two(or one, since two elements are equal) for such a,b,c to exist

let’s say x=min(a,b) , y=min(b,c) , z= min(c,a)

now if any of the following three conditions are true then there exists a solution

  1. x==y && z>=x
  2. y==z && x>=y
    3.x==z && y>=x

bro , tuple (4,2,5) is valid for min values (2,2,4).
for input (2,2,4) it will be YES !