Algorithm

Problem Name: 2 AD-HOC - beecrowd | 1410

He is Offside!

By Fábio Dias Moreira Brazil

Timelimit: 1

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.

 Sample Input Sample Output 2 3 500 700 700 500 500 2 2 200 400 200 1000 3 4 530 510 490 480 470 50 310 0 0 N Y N

Code Examples

#1 Code Example with C++ Programming

```Code - C++ Programming```

``````
#include <algorithm>
#include <iostream>
#include <list>
#include <queue>
#include <set>
#include <vector>
#define mp make_pair
#define pb push_back

using namespace std;

int a, d;
int ata[12];

int main()
{
ios::sync_with_stdio(false);
while (cin >> a >> d && a + d) {
priority_queue < int> pq;
int def, def1, def2;
for (int i = 0; i  <  a; ++i)
cin >> ata[i];
for (int i = 0; i  <  d; ++i) {
cin >> def;
pq.push(-def);
}
def1 = -pq.top();
pq.pop();
def2 = -pq.top();
pq.pop();
bool flag = false;
for (int i = 0; i  <  a; i++) {
if (ata[i] >= def2 || (ata[i] >= def1 && ata[i] >= def2))
;
else {
cout << "Y\n";
flag = true;
break;
}
}
if (!flag)
cout << "N\n";
}

return 0;
}
``````
Copy The Code &

Input

cmd
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

cmd
N
Y
N

#2 Code Example with Python Programming

```Code - Python Programming```

``````
while True:
a, d = [int(x) for x in input().split()]
if a == d == 0: break
da = min([int(x) for x in input().split()])
dd = sorted([int(x) for x in input().split()])[1]
if da < dd: print('Y')
else: print('N')
``````
Copy The Code &

Input

cmd
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

cmd
N
Y
N