OFFSIDE - He is offside!

no tags 

Hemisphere Network is the largest television network in Tumbolia, a small country located east of South America (or south of East America). The most popular sport in Tumbolia, unsurprisingly, is soccer; many games are broadcast every week in Tumbolia.

Hemisphere Network receives many requests to replay dubious plays; usually, these happen when a player is deemed to be offside by the referee. An attacking player is offside if he is nearer to his opponents’ goal line than the second last opponent. A player is not offside if

  • he is level with the second last opponent or

  • he is level with the last two opponents.

Through the use of computer graphics technology, Hemisphere Network can take an image of the field and determine the distances of the players to the defending team’s goal line, but they still need a program that, given these distances, decides whether a player is offside.


The input file contains several test cases. The first line of each test case contains two integers A and D separated by a single space indicating, respectively, the number of attacking and defending players involved in the play (2 <= A,D <= 11). The next line contains A integers Bi separated by single spaces, indicating the distances of the attacking players to the goal line (1 <= Bi <= 104). The next line contains D integers Cj separated by single spaces, indicating the distances of the defending players to the goal line (1 <= Cj <= 104). The end of input is indicated by A = D = 0.


For each test case in the input print a line containing a single character: “Y” (uppercase) if there is an attacking player offside, and “N” (uppercase) otherwise.


2 3
500 700
700 500 500
2 2
200 400
200 1000
3 4
530 510 490
480 470 50 310
0 0


hide comments
nemocptn3m0: 2018-06-01 16:07:40

AC in one go!!

kkislay20: 2018-03-16 15:40:49

If you get the ques, its a waste of time.

yatharth01: 2018-02-27 20:22:00

AC in one go!. Question statement is not clear. If you understand the question ,its very simple.

ayusofayush: 2018-02-22 17:50:15

problem statement is very poor....
better sort both the array and check .....

bradyawn: 2018-01-26 00:27:55

The problem statement is written very poorly

Ignore the "A player is not offside if
- he is level with the second last opponent or
- he is level with the last two opponents."

It is completely wrong

nitisha1: 2017-09-05 06:53:31

AC in 1 GO!!!!

madhur4127: 2017-08-22 15:14:07

AC in 1 GO!!
only one condition required!

vishal3410: 2017-07-15 15:54:01

AC in one go

abs_123: 2017-05-29 15:47:23

problem statement is not clear!
It just means "if two defenders are closer to goal line than attacker, then attacker is not offside" .

shubham_1234: 2017-04-11 22:45:18

AC in one go

Added by:Camilo Andrés Varela León
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:The 2007 ACM South American Programming Contest