Page Contents

## Arrange Guest

Prepbuddy is the manager of the marriage hall and he gets a booking for the biggest marriage in the town. The hall has N×MN×M seats, arranged in NN rows, MM seats in each row. Each seat has two coordinates (X,Y)(X,Y).

On the marriage day, there are two queues of guests waiting to enter the hall: KK people are standing at (0,0)(0,0) and N∗M−KN∗M−K people are standing at (0,M+1)(0,M+1). Each guest should have a ticket for a specific seat. If person PP at (X,Y)(X,Y) has ticket for seat (Xp,Yp)(Xp,Yp) then he should walk |X−Xp|+|Y−Yp||X−Xp|+|Y−Yp| to get to his seat.

Each person has stamina, the maximum distance, that the person agrees to walk. Prepbuddy has not managed this big ceremony before so help prepbuddy find out whether he can distribute all N∗MN∗M tickets in such a way that each person has enough stamina to get to their seat.

### Input Format

The first line of input contains two integers NN and MM. The second line contains several integers. The first integer KK, the number of people at (0,0)(0,0). The following KK integers indicate the stamina of each person there. The third line also contains several integers. The first integer LL, the number of people at (0,M+1)(0,M+1). The following LL integers indicate the stamina of each person there.

The stamina of the person is a positive integer less than or equal to N+MN+M.

### Output Format

If it is possible to distribute tickets between guests in the described manner print “YES”, otherwise print “NO”.

### Constraints

1≤N∗M≤1041≤N∗M≤104 0≤K≤N∗M0≤K≤N∗M L=N∗M−KL=N∗M−K

### Time Limit

2 second

### Example

#### Sample Input 1

2 2 3 3 3 2 1 3

#### Sample Output 1

YES

#### Sample Input 2

2 2 3 2 3 3 1 2

#### Sample Output 2

NO

Note : Please click on 1 or 2 ads to help us run this site and encourages us to provide you the solutions.

*JULY 2021 CODING MARATHON*

- Shortest String Solution
- Least Common Multiple Solution
- String Transformation Solution
- Dark Moments Solution
- Go Go Home Solution
- Construct Rectangle Solution
- Arrange Guest Solution
- New Array Subarray Solution