CF2244D.Yaroslav and Productivity

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Yaroslav's productivity during the day is described by an array aa of length nn. His productivity can be negative if he watches short videos, or positive if he works. The total productivity is defined as the sum of all values in the array.

Sometimes Yaroslav reads motivational posts. He has mm posts, where the jj-th post has an impact value bjb_j. If Yaroslav reads a post with value bjb_j, then all productivity values from the beginning of the day up to position bjb_j change sign, that is, all integers a1,a2,a3,…,abja_1, a_2, a_3, \dots, a_{b_j} are multiplied by −1-1.

For example, let a=[1,−4,3,−4]a = [1, -4, 3, -4], and Yaroslav reads a post with value 33. Then the signs of the first three elements are flipped, and the array becomes [−1,4,−3,−4][-1, 4, -3, -4]. If he then reads a post with value 11, the first element changes sign again, and the array becomes [1,4,−3,−4][1, 4, -3, -4].

What is the maximum possible total productivity Yaroslav can achieve by reading any (possibly none) of the posts?

Yaroslav 在一天中的工作效率由一个长度为 nn 的数组 aa 描述。他的工作效率可能为负(例如当他观看短视频时),也可能为正(例如当他工作时)。总工作效率定义为该数组中所有数值的和。

有时 Yaroslav 会阅读励志帖子。他共有 mm 个帖子,其中第 jj 个帖子的影响值为 bjb_j。若 Yaroslav 阅读了一个影响值为 bjb_j 的帖子,则当天从开始到位置 bjb_j 的所有工作效率值都将变号,即所有整数 a1,a2,a3,…,abja_1, a_2, a_3, \dots, a_{b_j} 均乘以 −1-1。

例如,设 a=[1,−4,3,−4]a = [1, -4, 3, -4],而 Yaroslav 阅读了一个影响值为 33 的帖子。那么前三个元素的符号被翻转,数组变为 [−1,4,−3,−4][-1, 4, -3, -4]。若他随后又阅读了一个影响值为 11 的帖子,则第一个元素再次变号,数组变为 [1,4,−3,−4][1, 4, -3, -4]。

通过阅读任意(可能为空)一组帖子,Yaroslav 能够达到的最大总工作效率是多少?

输入格式

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

The first line of each test case contains two integers nn and mm (1≤m≤n≤2⋅1051 \le m \le n \le 2 \cdot 10^5) — the number of measurements and the number of motivational posts.

The second line of each test case contains nn integers aia_i (−109≤ai≤109-10^9 \le a_i \le 10^9) — the productivity values.

The third line of each test case contains mm integers bib_i (1≤bi≤n1 \le b_i \le n) — the impact values of the posts. It is guaranteed that all bib_i are distinct.

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

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

每个测试用例的第一行包含两个整数 nn 和 mm(1≤m≤n≤2⋅1051 \le m \le n \le 2 \cdot 10^5)——测量次数和激励帖子的数量。

每个测试用例的第二行包含 nn 个整数 aia_i(−109≤ai≤109-10^9 \le a_i \le 10^9)——生产力值。

每个测试用例的第三行包含 mm 个整数 bib_i(1≤bi≤n1 \le b_i \le n)——帖子的影响值。保证所有 bib_i 互不相同。

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

输出格式

For each test case, output a single integer — the maximum possible total productivity.

对于每个测试用例,输出一个整数——可能的最大总生产力。

输入输出样例

  • 输入#1

    4
    5 3
    -1 2 -3 4 -5
    1 5 3
    4 2
    3 -1 3 -1
    4 2
    3 1
    -5 -5 -5
    2
    4 3
    3 -1 1 -3
    4 3 2

    输出#1

    3
    4
    5
    6

说明/提示

null

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

首页