Controllers
Time limit2sMemory limit1024 MB
Given a string of + and - round symbols, decide for each pair of button values whether pressing one button per round can bring the final score to exactly 0.
- Level
Medium4 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
You are at your grandparents' house and playing an old video game on a strange console. Your controller has only two buttons, and each button has a number written on it.
Initially, your score is . The game has rounds. For each , round works as follows.
A symbol appears on the screen. It is either + or -. Then you must press one of the two buttons exactly once. If you press a button with the number written on it, your score increases by when the symbol is +, and decreases by when the symbol is -. The round ends after you press the button.
After all rounds, you win if your score is .
Your grandparents have bought many different controllers over the years, so there are of them. The two buttons on the -th controller have the numbers and . For each controller, determine whether you can win the game with it.
Input
The first line contains an integer (), the number of rounds.
The second line contains a string of length , where is the symbol shown in round . contains only the characters + and -.
The third line contains an integer (), the number of controllers.
Each of the next lines contains two integers and ().
Output
Print lines. On line , print YES if you can win the game with the -th controller, and NO otherwise.