Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 300 点
問題文
X
, Y
からなる長さ N の文字列 S であって,以下の条件を満たすものが存在するかどうかを判定してください.
条件: S 中で 2 つの文字が隣り合う (N - 1) 箇所のうち
- ちょうど A 個が
XX
, - ちょうど B 個が
XY
, - ちょうど C 個が
YX
, - ちょうど D 個が
YY
である.
制約
- 1 \leq N \leq 2 \times 10^5
- A \geq 0
- B \geq 0
- C \geq 0
- D \geq 0
- A + B + C + D = N - 1
入力
入力は以下の形式で標準入力から与えられる.
N A B C D
出力
条件を満たす文字列 S が存在するなら Yes
を,存在しないなら No
を出力せよ.
入力例 1
5 1 1 1 1
出力例 1
Yes
たとえば S = {}XXYYX
とすると,2 つの文字が隣り合う箇所は左から順に XX
, XY
, YY
, YX
であり,各 1 個ずつとなって条件を満たします.
入力例 2
5 1 2 1 0
出力例 2
Yes
たとえば S = {}XXYXY
が条件を満たします.
入力例 3
5 0 4 0 0
出力例 3
No
条件を満たす文字列は存在しません.
Score : 300 points
Problem Statement
Determine whether there is a string S of length N consisting of X
and Y
that satisfies the following condition.
Condition: Among the (N - 1) pairs of consecutive characters in S,
- exactly A are
XX
, - exactly B are
XY
, - exactly C are
YX
, and - exactly D are
YY
.
Constraints
- 1 \leq N \leq 2 \times 10^5
- A \geq 0
- B \geq 0
- C \geq 0
- D \geq 0
- A + B + C + D = N - 1
Input
The input is given from Standard Input in the following format:
N A B C D
Output
If there is a string S that satisfies the condition, print Yes
; otherwise, print No
.
Sample Input 1
5 1 1 1 1
Sample Output 1
Yes
For instance, if S = {}XXYYX
, the pairs of consecutive characters are XX
, XY
, YY
, and YX
from left to right. Each pattern occurs exactly once, so the condition is satisfied.
Sample Input 2
5 1 2 1 0
Sample Output 2
Yes
For instance, S = {}XXYXY
satisfies the condition.
Sample Input 3
5 0 4 0 0
Sample Output 3
No
No string satisfies the condition.