CABS Editorial

PROBLEM LINK:

Contest Division 1
Contest Division 2
Contest Division 3
Contest Division 4

Setter: Jeevan Mayur Koli
Testers: Abhinav Sharma, Nishank Suresh
Editorialist: Pratiyush Mishra

DIFFICULTY:

Cakewalk

PREREQUISITES:

None

PROBLEM:

Chef has to travel to another place. For this, he can avail any one of two cab services.

  • The first cab service charges X rupees.
  • The second cab service charges Y rupees.
    Chef wants to spend the minimum amount of money. Which cab service should Chef take?

EXPLANATION:

For each test case, we have to compare which of the cabs, first or the second incurs lesser charge.
This can be done by comparing the first cab and the second cab charges. If the first cab costs less we have to print FIRST, otherwise if the second cab costs less we have to print SECOND and in the case where both charge equally we have to print ANY.

TIME COMPLEXITY:

O(1) for each test case.

SOLUTION:

Editorialist’s Solution
Setter’s Solution
Tester 1’s Solution
Tester 2’s Solution

import java.util.*;
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while(t>0)
		{
		    int n1= sc.nextInt();
		    int n2= sc.nextInt();
		    System.out.println(n1 == n2 ? "ANY": n1 < n2 ? "FIRST" : "SECOND");
		    t--;
		}
	}
}