CF2179E.Blackslex and Girls

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

After failing to pick up a girl using De Bruijn sequence of fixed-length bitstrings, Blackslex has turned his attention towards politics.

Due to his high charisma, he is now in charge of drawing borders for the nn voting districts of his country. In Blackslex's country, there are xx voters for party A and yy voters for party B. Using his amazing drawing skills, he can allocate voters from any party into any district of his choice.

His history with bitstrings has led him to wonder if he can allocate voters such that the winner of each district follows a certain bitstring pattern. To avoid suspicion, he must also allocate at least pip_i voters into each district. Tell him if it is possible!

Formally, you are given a binary string ss of length nn, an array pp of length nn, and two integers xx and yy.

You want to determine whether there exist two arrays of nonnegative integers aa and bb of length nn that satisfy the following conditions:

  • a1+a2+⋯+an=xa_1 + a_2 + \dots + a_n = x
  • b1+b2+⋯+bn=yb_1 + b_2 + \dots + b_n = y
  • For every 1≤i≤n1 \leq i \leq n, ai+bi≥pia_i + b_i \geq p_i
  • For every 1≤i≤n1 \leq i \leq n:
    • If si=0s_i = 0 then ai>bia_i \gt b_i
    • If si=1s_i = 1 then bi>aib_i \gt a_i

在尝试用固定长度二进制字符串的德布鲁因序列(De Bruijn sequence)搭讪失败后,Blackslex 将注意力转向了政治。

凭借其极高的个人魅力,他如今负责为其国家的 nn 个选区划定边界。在 Blackslex 的国家中,有 xx 名政党 A 的选民和 yy 名政党 B 的选民。凭借他惊人的绘图技巧,他可以将任意政党的选民分配至任意他选定的选区。

他对二进制字符串的研究经历使他开始思考:能否将选民进行分配,使得每个选区的获胜政党恰好符合给定的二进制字符串模式?为避免引起怀疑,他还必须确保每个选区至少包含 pip_i 名选民。请告诉他这是否可行!

形式化地,你将获得一个长度为 nn 的二进制字符串 ss、一个长度为 nn 的数组 pp,以及两个整数 xx 和 yy。

你需要判断是否存在两个长度为 nn 的非负整数数组 aa 和 bb,满足以下条件:

  • a1+a2+⋯+an=xa_1 + a_2 + \dots + a_n = x
  • b1+b2+⋯+bn=yb_1 + b_2 + \dots + b_n = y
  • 对每个 1≤i≤n1 \leq i \leq n,均有 ai+bi≥pia_i + b_i \geq p_i
  • 对每个 1≤i≤n1 \leq i \leq n:
    • 若 si=0s_i = 0,则 ai>bia_i \gt b_i
    • 若 si=1s_i = 1,则 bi>aib_i \gt a_i

输入格式

The first line contains a single integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases.

The first line of each test case contains three integers nn, xx, and yy (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5, 1≤x,y≤1091 \leq x, y \leq 10^9).

The second line contains a binary string ss of length nn.

The third line contains nn integers p1,p2,…,pnp_1, p_2, \dots, p_n (1≤pi≤1091 \leq p_i \leq 10^9).

The sum of nn across all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4)——测试用例的数量。

每个测试用例的第一行包含三个整数 nn、xx 和 yy(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5,1≤x,y≤1091 \leq x, y \leq 10^9)。

第二行包含一个长度为 nn 的二进制字符串 ss。

第三行包含 nn 个整数 p1,p2,…,pnp_1, p_2, \dots, p_n(1≤pi≤1091 \leq p_i \leq 10^9)。

所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, print (case-insensitive) YES if there exist arrays a,ba, b satisfying all conditions, or NO otherwise.

对于每个测试用例,如果存在满足所有条件的数组 a,ba, b,则输出(不区分大小写)YES;否则输出 NO。

输入输出样例

  • 输入#1

    6
    3 5 5
    010
    2 4 3
    4 2 3
    0001
    1 1 1 1
    2 4 2
    00
    3 3
    4 23 20
    1111
    2 2 2 2
    1 25 26
    0
    51
    2 4 2
    00
    3 4

    输出#1

    YES
    NO
    YES
    NO
    NO
    NO

说明/提示

In the first test case, one of the possible distributions of voters is: a=[2,0,3]a = [2, 0, 3] and b=[0,4,1]b = [0, 4, 1].

In the third test case, one of the possible distributions of voters is: a=[2,2]a = [2, 2] and b=[1,1]b = [1, 1].

For the other test cases, it can be shown that there are no distributions of voters that satisfy the conditions.

在第一个测试用例中,一种可能的选民分布为:a=[2,0,3]a = [2, 0, 3] 和 b=[0,4,1]b = [0, 4, 1]。

在第三个测试用例中,一种可能的选民分布为:a=[2,2]a = [2, 2] 和 b=[1,1]b = [1, 1]。

对于其余测试用例,可以证明不存在满足条件的选民分布。

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

首页