Logo
(追記) (追記ここまで)

27600번 - Controllers 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB56403975.000%

문제

You are at your grandparents’ house and you are 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 0ドル$. The game is composed of $n$ rounds. For each 1ドル ≤ i ≤ n,ドル the $i$-th round works as follows.

On the screen, a symbol $s_i$ appears, which is either + (plus) or - (minus). Then you must press one of the two buttons on the controller once. Suppose you press a button with the number $x$ written on it: your score will increase by $x$ if the symbol was + and will decrease by $x$ if the symbol was -. After you press the button, the round ends.

After you have played all $n$ rounds, you win if your score is 0ドル$.

Over the years, your grandparents bought many different controllers, so you have $q$ of them. The two buttons on the $j$-th controller have the numbers $a_j$ and $b_j$ written on them. For each controller, you must compute whether you can win the game playing with that controller.

입력

The first line contains a single integer $n$ (1ドル ≤ n ≤ 2 \cdot 10^5$) — the number of rounds.

The second line contains a string $s$ of length $n$ — where $s_i$ is the symbol that will appear on the screen in the $i$-th round. It is guaranteed that $s$ contains only the characters + and -.

The third line contains an integer $q$ (1ドル ≤ q ≤ 10^5$) — the number of controllers.

The following $q$ lines contain two integers $a_j$ and $b_j$ each (1ドル ≤ a_j , b_j ≤ 10^9$) — the numbers on the buttons of controller $j$.

출력

Output $q$ lines. On line $j$ print YES if the game is winnable using controller $j,ドル otherwise print NO.

제한

예제 입력 1

8
+-+---+-
5
2 1
10 3
7 9
10 10
5 3

예제 출력 1

YES
NO
NO
NO
YES

One possible way to get score 0ドル$ using the first controller is by pressing the button with number 1ドル$ in rounds 1ドル,ドル 2ドル,ドル 4ドル,ドル 5ドル,ドル 6ドル$ and 8ドル,ドル and pressing the button with number 2ドル$ in rounds 3ドル$ and 7ドル$. It is possible to show that there is no way to get a score of 0ドル$ using the second controller.

예제 입력 2

6
+-++--
2
9 7
1 1

예제 출력 2

YES
YES

예제 입력 3

20
+-----+--+--------+-
2
1000000000 99999997
250000000 1000000000

예제 출력 3

NO
YES

힌트

출처

ICPC > Regionals > Europe > Southwestern European Regional Contest > SWERC 2022-2023 H번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /