Codeforces Round 1099 (Div. 2)
D
最大前缀和
Maximum Prefix Sums
Codeforces
1900
原题
← CE →

最大前缀和AI (CI翻译)

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.

521 在中文中与“我爱你”谐音。在这个特殊的日子里,小 S 想送给小 A 一些精心准备的序列,以回忆他们维系多年的友谊。AI (CI翻译)

Little S has prepared an array $a_1, a_2, \ldots, a_n$. Let's define its prefix sums array $b_1, b_2, \ldots, b_n$, where $b_i = a_1 + a_2 + \ldots + a_i$. Also define the prefix maximum array of $b$: $c_1, c_2, \ldots, c_n$, where $c_i = \max(b_1, b_2, \ldots, b_i)$.

小 S 准备了一个数组 $a_1, a_2, \ldots, a_n$。定义它的前缀和数组 $b_1, b_2, \ldots, b_n$,其中 $b_i = a_1 + a_2 + \ldots + a_i$。再定义 $b$ 的前缀最大值数组 $c_1, c_2, \ldots, c_n$,其中 $c_i = \max(b_1, b_2, \ldots, b_i)$。AI (CI翻译)

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.

现在,数组 $a$ 的部分元素丢失了,但幸运的是小 S 仍然保留着数组 $c$。你的任务是还原数组 $a$ 并将其送给小 A,或者报告不存在这样的数组——在这种情况下,善良可爱的小 A 也不会生气。AI (CI翻译)

Formally, you are given a binary string $s$, a partially filled array $a$, and an array $c$, where:

形式化地说,给定一个二进制字符串 $s$、一个部分填充的数组 $a$ 和一个数组 $c$,其中:AI (CI翻译)

  • If you remember the value of $a_i$, then $s_i = 1$, and you are given the true value of $a_i$.
  • If you do not remember the value of $a_i$, then $s_i = 0$, and you are given $a_i = 0$.
  • 如果你记得 $a_i$ 的值,则 $s_i = 1$,并且给出 $a_i$ 的真实值。
  • 如果你不记得 $a_i$ 的值,则 $s_i = 0$,并且给出 $a_i = 0$。
AI (CI翻译)

Input

输入

AI (CI翻译)

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

每个测试包含多个测试用例。第一行包含测试用例的数量 $t$($1 \le t \le 10^4$)。接下来是各个测试用例的描述。AI (CI翻译)

The first line of each test case contains an integer $n$ ($1 \le n \le 2 \cdot 10^5$).

每个测试用例的第一行包含一个整数 $n$($1 \le n \le 2 \cdot 10^5$)。AI (CI翻译)

The second line of each test case contains a binary string $s$ ($s_i \in \{\texttt{0}, \texttt{1}\}$) of length $n$.

每个测试用例的第二行包含一个长度为 $n$ 的二进制字符串 $s$($s_i \in \{\texttt{0}, \texttt{1}\}$)。AI (CI翻译)

The third line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($|a_i| \le 10^6$). If $s_i = \texttt{0}$, then it is guaranteed that $a_i = 0$.

每个测试用例的第三行包含 $n$ 个整数 $a_1, a_2, \ldots, a_n$($|a_i| \le 10^6$)。如果 $s_i = \texttt{0}$,则保证 $a_i = 0$。AI (CI翻译)

The fourth line of each test case contains $n$ integers $c_1, c_2, \ldots, c_n$ ($|c_i| \le 2 \cdot 10^{11}$).

每个测试用例的第四行包含 $n$ 个整数 $c_1, c_2, \ldots, c_n$($|c_i| \le 2 \cdot 10^{11}$)。AI (CI翻译)

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.

保证所有测试用例中 $n$ 的总和不超过 $2 \cdot 10^5$。AI (CI翻译)

Output

输出

AI (CI翻译)

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.

对于每个测试用例,如果数组 $a$ 存在,在第一行输出 Yes,否则输出 No。答案可以使用任意大小写形式。例如,YeS、YES、NO、nO 也会被接受。AI (CI翻译)

If there is at least one solution, print $n$ integers $a_1, a_2, \ldots, a_n$ ($|a_i| \leq 10^{18}$) in the second line. If there are multiple suitable arrays, you may print any of them.

如果至少存在一个解,则在第二行输出 $n$ 个整数 $a_1, a_2, \ldots, a_n$($|a_i| \le 10^{18}$)。如果有多个满足条件的数组,可以输出其中任意一个。AI (CI翻译)

Note

说明

AI (CI翻译)

In the first test case, we have:

在第一个测试用例中:AI (CI翻译)

  • $a = [1, 2, -1, 0]$.
  • $b = [1, 3, 2, 2]$.
  • $c = [1, 3, 3, 3]$.
  • $a = [1, 2, -1, 0]$。
  • $b = [1, 3, 2, 2]$。
  • $c = [1, 3, 3, 3]$。
AI (CI翻译)

In the third test case, the correct array $a$ should be equal to $[1]$, so no solution exists.

在第三个测试用例中,正确的数组 $a$ 应为 $[1]$,因此不存在解。AI (CI翻译)

样例

Input #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
Output #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
InputCopy OutputCopy
题目信息
题号
2231D
时间限制
2 s
内存限制
256 MB
标签
构造
贪心
模拟
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。