CF2231D.Maximum Prefix Sums
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
521 sounds the same as "I love you" in Chinese. On this special day, Little S wants to give Little A some well-prepared sequences to recall their friendship sealed for years.
Little S has prepared an array a1,a2,…,an. Let's define its prefix sums array b1,b2,…,bn, where bi=a1+a2+…+ai. Also define the prefix maximum array of b: c1,c2,…,cn, where ci=max(b1,b2,…,bi).
Now array a has been partially lost, but luckily Little S still keeps the array c. Your task is to restore the array a and send it to Little A, or report that no such array exists — in this case, the kind and cute Little A won't get mad either.
Formally, you are given a binary string s, a partially filled array a, and an array c, where:
- If you remember the value of ai, then si=1, and you are given the true value of ai.
- If you do not remember the value of ai, then si=0, and you are given ai=0.
521 在中文中与 “I love you” 谐音。在这个特别的日子里,小 S 想要送给小 A 一些精心准备的数列,以唤起他们多年以来牢不可破的友谊。
小 S 已准备好一个数组 a1,a2,…,an。我们定义其前缀和数组为 b1,b2,…,bn,其中 bi=a1+a2+…+ai;再定义 b 的前缀最大值数组 c1,c2,…,cn,其中 ci=max(b1,b2,…,bi)。
目前数组 a 已部分丢失,但幸运的是,小 S 仍保留着数组 c。你的任务是根据 c 恢复出原数组 a 并将其发送给小 A;若不存在满足条件的数组,则报告无解——此时善良又可爱的小 A 也不会生气哦。
形式化地,你将获得一个二进制字符串 s、一个部分填充的数组 a 以及一个数组 c,满足:
- 若你记得 ai 的值,则 si=1,且你被给出真实的 ai 值;
- 若你不记得 ai 的值,则 si=0,且你被给出 ai=0。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains an integer n (1≤n≤2⋅105).
The second line of each test case contains a binary string s (si∈0,1) of length n.
The third line of each test case contains n integers a1,a2,…,an (∣ai∣≤106). If si=0, then it is guaranteed that ai=0.
The fourth line of each test case contains n integers c1,c2,…,cn (∣ci∣≤2⋅1011).
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105)。
每个测试用例的第二行包含一个长度为 n 的二进制字符串 s(其中 si∈{0,1})。
每个测试用例的第三行包含 n 个整数 a1,a2,…,an(∣ai∣≤106)。若 si=0,则保证 ai=0。
每个测试用例的第四行包含 n 个整数 c1,c2,…,cn(∣ci∣≤2⋅1011)。
保证所有测试用例的 n 值之和不超过 2⋅105。
输出格式
For each test case, print "Yes" in the first line if the array a exists, otherwise print "No". You may print the answer in any case. For example, "YeS", "YES", "NO", "nO" will also be accepted.
If there is at least one solution, print n integers a1,a2,…,an (∣ai∣≤1018) in the second line. If there are multiple suitable arrays, you may print any of them.
对于每个测试用例,如果数组 a 存在,则在第一行输出 "Yes";否则输出 "No"。你可以以任意大小写形式输出答案,例如 "YeS"、"YES"、"NO"、"nO" 均可接受。
如果至少存在一个解,则在第二行输出 n 个整数 a1,a2,…,an(满足 ∣ai∣≤1018)。如果存在多个合适的数组,你可以输出其中任意一个。
输入输出样例
输入#1
10 4 1110 1 2 -1 0 1 3 3 3 5 00001 0 0 0 0 5 -4 -4 -1 -1 -1 1 1 0 1 6 001111 0 0 2 -3 3 -6 -5 -2 0 0 0 0 5 11110 1 2 0 5 0 1 2 2 7 6 2 01 0 1 -1 -1 6 001010 0 0 5 0 3 0 3 3 4 9 13 16 6 000100 0 0 0 4 0 0 2 6 6 7 7 7 2 00 0 0 4 -1 8 11111111 6 1 1 2 0 5 1 9 6 7 8 10 10 15 16 25
输出#1
Yes 1 2 -1 0 Yes -4 0 3 -6 5 No Yes -5 3 2 -3 3 -6 No No No Yes 2 4 -3 4 -100 0 No Yes 6 1 1 2 0 5 1 9
说明/提示
In the first test case, we have:
- a=[1,2,−1,0].
- b=[1,3,2,2].
- c=[1,3,3,3].
In the third test case, the correct array a should be equal to [1], so no solution exists.
在第一个测试用例中,我们有:
- a=[1,2,−1,0]。
- b=[1,3,2,2]。
- c=[1,3,3,3]。
在第三个测试用例中,正确的数组 a 应等于 [1],因此不存在解。
输入解题思路,AI测评打分。不知道怎么写?