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.

Input

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.

Output

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.

Example

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

Output:
N
Y
N

hide comments
puneethnaik: 2016-05-20 10:27:00

My 26th!!More to come!Good problem

divyaprakash18: 2016-05-05 14:26:14

Hah !! Easy one !! Simple logic !! Got CE first but succeeded in second :)

uzumaki_75: 2016-02-13 16:12:11

My 25th -_-

archit saxena: 2015-12-19 18:45:35

Its all about the minimum. :D

Gosh, who the hell named the problem setter. All the words are football players.
copied from a previous comment but a nice one
1. Camlio Sanvezzo(Brazil)
2. Andres Iniesta(Spain)
3. Silvestre Varela(POrtugal)
4. Pedro Leon(Spain)

Last edit: 2015-12-19 18:47:02
sarthak_8: 2015-12-19 18:26:01

Easy one .. AC in one go .. 25th on SPOJ .. Feeling Good !! :)

jazzbro: 2015-12-10 19:20:47

first sort the distances of both attacker's and defender's distance, otherwise it would case a WA :(

Siddharth Singh: 2015-12-08 08:23:51

Forget The Problem Statement
Attacker Is not Offside if two defenders are closer to goal than him

Last edit: 2015-12-08 08:25:46
RADHE SHYAM LODHI: 2015-08-30 14:13:09

An attacking player is offside if he is nearer to his opponents’ goal line than the second last opponent , Nothing beyond this statement

mehul712: 2015-08-26 16:16:22

was getting nzec as had defined 'Scanner' object in loop...

bhuvnesh13396: 2015-07-27 08:19:02

too confusing problem statement..!!!


Added by:Camilo Andrés Varela León
Date:2007-12-02
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