CF884B.Japanese Crosswords Strike Back

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and a__i is the length of i-th segment. No two segments touch or intersect.

For example:

  • If x = 6 and the crossword is 111011, then its encoding is an array {3, 2};
  • If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1};
  • If x = 5 and the crossword is 11111, then its encoding is an array {5};
  • If x = 5 and the crossword is 00000, then its encoding is an empty array.

Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!

一维日本填字游戏可以表示为一个长度为 xx 的二进制字符串。该填字游戏的编码是一个大小为 nn 的数组 aa,其中 nn 是由连续的 1 构成的段(即全 1 段)的数量,而 aia_i 表示第 ii 个段的长度。任意两个段互不接触、也不相交。

例如:

  • 若 x=6x = 6,且填字游戏为 111011,则其编码为数组 {3, 2}\{3,\,2\};
  • 若 x=8x = 8,且填字游戏为 01101010,则其编码为数组 {2, 1, 1}\{2,\,1,\,1\};
  • 若 x=5x = 5,且填字游戏为 11111,则其编码为数组 {5}\{5\};
  • 若 x=5x = 5,且填字游戏为 00000,则其编码为空数组。

米什卡想创作一个新的一维日本填字游戏。他已选定该填字游戏的长度及其编码。现在,他需要验证:是否存在唯一一个填字游戏,其长度和编码恰好等于他所选定的长度与编码。请帮助他完成这一验证!

输入格式

The first line contains two integer numbers n and x (1 ≤ n ≤ 100000, 1 ≤ x ≤ 109) — the number of elements in the encoding and the length of the crossword Mishka picked.

The second line contains n integer numbers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 10000) — the encoding.

第一行包含两个整数 nn 和 xx(1≤n≤1000001 \leq n \leq 100000,1≤x≤1091 \leq x \leq 10^9)—— 分别表示编码中的元素个数以及米什卡所选填字游戏的长度。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤100001 \leq a_i \leq 10000)—— 表示该编码。

输出格式

Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.

如果存在唯一一个满足所选长度和编码的填字游戏,则输出 YES;否则输出 NO。

输入输出样例

  • 输入#1

    2 4
    1 3

    输出#1

    NO
  • 输入#2

    3 10
    3 3 2

    输出#2

    YES
  • 输入#3

    2 10
    1 3

    输出#3

    NO

输入解题思路,AI测评打分。不知道怎么写?

首页