Determine the Winner solution codechef

Determine the Winner solution codechef

There is a contest containing 22 problems AA and BB.

22 strong participants PP and QQ participated in the contest and solved both the problems.

PP made AC submissions on problems AA and BB at time instants PAPA and PBPB respectively while QQ made AC submissions on problems AA and BB at time instants QAQA and QBQB.

It is given that the time penalty is the minimum time instant at which a participant has solved both the problems. Also the participant with the lower time penalty will have a better rank.

Determine which participant got the better rank or if there is a TIE.

Determine the Winner solution codechef 

Input Format

  • The first line will contain TT, number of test cases. Then the test cases follow.
  • Each test case contains a single line of input, four integers PA,PB,QA,QBPA,PB,QA,QB.

Output Format

For each test case, output P if PP got a better rank, Q if QQ got a better rank, TIE otherwise.

Note that output is case-insensitive i.e. P and p both are considered the same.


Determine the Winner solution codechef

  • 1T10001≤T≤1000
  • 1PA,PB,QA,QB1001≤PA,PB,QA,QB≤100

Sample Input 1 

5 10 2 12
10 30 15 15
20 8 4 20
6 6 6 6

Sample Output 1 



Determine the Winner solution codechef

Test Case 11:

  • Time penalty incurred by participant P=10P=10.
  • Time penalty incurred by participant Q=12Q=12.

Since 10<1210<12PP gets a better rank.

Test Case 22:

  • Time penalty incurred by participant P=30P=30.
  • Time penalty incurred by participant Q=15Q=15.

Since 15<3015<30QQ gets a better rank.

Test Case 33:

  • Time penalty incurred by participant P=20P=20.
  • Time penalty incurred by participant Q=20Q=20.

Since 20=2020=20PP and QQ gets a same rank (TIE).

Test Case 44:

  • Time penalty incurred by participant P=6P=6.
  • Time penalty incurred by participant Q=6Q=6.

Since 6=66=6PP and QQ gets a same rank (TIE).


Click Here

Leave a Comment

Your email address will not be published.