Bfs
시간 제한1초메모리 제한1024 MB
남학생 또는 여학생 두 명의 순서를 맞바꿀 때마다, 던지는 순서를 정해 막대의 기울기가 S를 넘지 않도록 할 수 있는지 판정한다.
문제
The kids from 402 heard the bell and quickly went outside to play. Seeing a big pole in the middle of the field they thought of the following game. Initially they split in groups of girls and boys (there are mm girls and 𝑛n boys) and then they position themselves somewhere on the field.
Initially the pole is completely vertical (has tilt ). Each player has certain force ( is the force of the th boy, is the force of the th girl). The game goes like this: at each step, either the boy or the girl closest to the pole (with the smallest index) throws a ball to the pole, after which he/she leaves the game. A boy's throw tilts the pole to the right, while a girl's throw tilts the pole to the left. The tilt of the pole changes with a value equal to the player's force.
In order to make sure the game doesn't end disastrously, the pole is not allowed to be tilted (in either direction) more than . The kids are wondering if they can find an order of throws such that this condition is respected.
To make things more interesting, their teacher chooses moments when she swaps the order of two consecutive boys or girls. All the swaps are persistent.
You should help the kids decide if there is a valid order of throws after each swap.
입력
The first line contains three integers , and .
The second line contains integers representing the force values of the boys.
The third line contains integers representing the force values of the girls.
The fourth line contains a single integer .
Each of the next lines is of the form , where represents the group of the swap ( stands for the boys' group, for the girls' group), while and are the swapped positions.
출력
Output lines, each containing if the game can be successful, or otherwise.
제한
- For every swap
- It is guaranteed that before the first swap the game is successful