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 n voting districts of his country. In Blackslex's country, there are x voters for party A and y 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 pi voters into each district. Tell him if it is possible!
Formally, you are given a binary string s of length n, an array p of length n, and two integers x and y.
You want to determine whether there exist two arrays of nonnegative integers a and b of length n that satisfy the following conditions:
- a1+a2+⋯+an=x
- b1+b2+⋯+bn=y
- For every 1≤i≤n, ai+bi≥pi
- For every 1≤i≤n:
- If si=0 then ai>bi
- If si=1 then bi>ai
在尝试用固定长度二进制字符串的德布鲁因序列(De Bruijn sequence)搭讪失败后,Blackslex 将注意力转向了政治。
凭借其极高的个人魅力,他如今负责为其国家的 n 个选区划定边界。在 Blackslex 的国家中,有 x 名政党 A 的选民和 y 名政党 B 的选民。凭借他惊人的绘图技巧,他可以将任意政党的选民分配至任意他选定的选区。
他对二进制字符串的研究经历使他开始思考:能否将选民进行分配,使得每个选区的获胜政党恰好符合给定的二进制字符串模式?为避免引起怀疑,他还必须确保每个选区至少包含 pi 名选民。请告诉他这是否可行!
形式化地,你将获得一个长度为 n 的二进制字符串 s、一个长度为 n 的数组 p,以及两个整数 x 和 y。
你需要判断是否存在两个长度为 n 的非负整数数组 a 和 b,满足以下条件:
- a1+a2+⋯+an=x
- b1+b2+⋯+bn=y
- 对每个 1≤i≤n,均有 ai+bi≥pi
- 对每个 1≤i≤n:
- 若 si=0,则 ai>bi
- 若 si=1,则 bi>ai
输入格式
The first line contains a single integer t (1≤t≤104) — the number of test cases.
The first line of each test case contains three integers n, x, and y (1≤n≤2⋅105, 1≤x,y≤109).
The second line contains a binary string s of length n.
The third line contains n integers p1,p2,…,pn (1≤pi≤109).
The sum of n across all test cases does not exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104)——测试用例的数量。
每个测试用例的第一行包含三个整数 n、x 和 y(1≤n≤2⋅105,1≤x,y≤109)。
第二行包含一个长度为 n 的二进制字符串 s。
第三行包含 n 个整数 p1,p2,…,pn(1≤pi≤109)。
所有测试用例中 n 的总和不超过 2⋅105。
输出格式
For each test case, print (case-insensitive) YES if there exist arrays a,b satisfying all conditions, or NO otherwise.
对于每个测试用例,如果存在满足所有条件的数组 a,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] and b=[0,4,1].
In the third test case, one of the possible distributions of voters is: a=[2,2] and 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] 和 b=[0,4,1]。
在第三个测试用例中,一种可能的选民分布为:a=[2,2] 和 b=[1,1]。
对于其余测试用例,可以证明不存在满足条件的选民分布。
输入解题思路,AI测评打分。不知道怎么写?