CF2244D.Yaroslav and Productivity
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Yaroslav's productivity during the day is described by an array a of length n. 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 m posts, where the j-th post has an impact value bj. If Yaroslav reads a post with value bj, then all productivity values from the beginning of the day up to position bj change sign, that is, all integers a1,a2,a3,…,abj are multiplied by −1.
For example, let a=[1,−4,3,−4], and Yaroslav reads a post with value 3. Then the signs of the first three elements are flipped, and the array becomes [−1,4,−3,−4]. If he then reads a post with value 1, the first element changes sign again, and the array becomes [1,4,−3,−4].
What is the maximum possible total productivity Yaroslav can achieve by reading any (possibly none) of the posts?
Yaroslav 在一天中的工作效率由一个长度为 n 的数组 a 描述。他的工作效率可能为负(例如当他观看短视频时),也可能为正(例如当他工作时)。总工作效率定义为该数组中所有数值的和。
有时 Yaroslav 会阅读励志帖子。他共有 m 个帖子,其中第 j 个帖子的影响值为 bj。若 Yaroslav 阅读了一个影响值为 bj 的帖子,则当天从开始到位置 bj 的所有工作效率值都将变号,即所有整数 a1,a2,a3,…,abj 均乘以 −1。
例如,设 a=[1,−4,3,−4],而 Yaroslav 阅读了一个影响值为 3 的帖子。那么前三个元素的符号被翻转,数组变为 [−1,4,−3,−4]。若他随后又阅读了一个影响值为 1 的帖子,则第一个元素再次变号,数组变为 [1,4,−3,−4]。
通过阅读任意(可能为空)一组帖子,Yaroslav 能够达到的最大总工作效率是多少?
输入格式
The first line contains a single integer t (1≤t≤104) — the number of test cases.
The first line of each test case contains two integers n and m (1≤m≤n≤2⋅105) — the number of measurements and the number of motivational posts.
The second line of each test case contains n integers ai (−109≤ai≤109) — the productivity values.
The third line of each test case contains m integers bi (1≤bi≤n) — the impact values of the posts. It is guaranteed that all bi are distinct.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104)——测试用例的数量。
每个测试用例的第一行包含两个整数 n 和 m(1≤m≤n≤2⋅105)——测量次数和激励帖子的数量。
每个测试用例的第二行包含 n 个整数 ai(−109≤ai≤109)——生产力值。
每个测试用例的第三行包含 m 个整数 bi(1≤bi≤n)——帖子的影响值。保证所有 bi 互不相同。
保证所有测试用例中 n 的总和不超过 2⋅105。
输出格式
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测评打分。不知道怎么写?