logo AlgoBeat OnlineJudge
登录 注册

#212169. [OOI 2025] The Arithmetic exercise

内存限制:256 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Oleg and Dasha participated in a team competition, but unfortunately, they were unable to solve any problems. Oleg immediately realized that their team wasn't training enough. Then, their mutual friend suggested an interesting exercise. The exercise was quite simple, and to solve it, they only needed to know the rules of addition and subtraction of integers.

You are given an array of length , where initially all values are zero. You are also given numbers . Then, for each from to , you choose some index and make the change .

Help Oleg and Dasha determine what the maximum possible sum of the elements of array can be after all the changes, if the choices are made optimally.

输入格式

Each test consists of several input data sets. The first line contains a single integer () --- the number of input data sets. Then follows the description of the data sets.

The first line of each data set contains two integers and () --- the length of the array and the number of values , respectively.

The second line of each data set contains integers , , , () --- the description of the values.

Let be the sum of over all data sets, and be the sum of over all data sets.

It is guaranteed that and do not exceed .

输出格式

For each data set, output a single number on a new line --- the maximum sum of the array that can be obtained.

样例

样例输入 1

4
1 4
1 2 3 4
2 7
10 3 7 1 4 6 3
4 10
103 354 1 227 179 189 142 201 165 140
5 3
-10 11 -4

样例输出 1

2
18
1085
17

数据范围与提示

Note

In the first data set, all operations are applied to the first element of the array . It sequentially becomes , , , , so the answer is .

In the second data set, the following sequence of changes can be performed:

  • Apply the change to the first element: , .
  • Apply the change to the first element: , .
  • Apply the change to the first element: , .
  • Apply the change to the first element: , .
  • Apply the change to the second element: , .
  • Apply the change to the first element: , .
  • Apply the change to the second element: , .

At the end, we have , so the final sum is .

It can be shown that a better result is not possible.

Scoring

The tests for this problem consist of ten groups. Points for each group are given only if all tests of the group and all tests of the required groups are passed. Please note that passing the example tests is not required for some groups. means that the results of testing your solution on this group will only be available after the end of the competition.

Group Points Additional constraints: Additional constraints: Additional constraints: Required Groups Comment
0 -- -- -- Examples.
1 4 All are same
2 8 , --
3 11
4 9 3
5 8 , , -- 0
6 10 --
7 12 -- 0, 2 -- 6
8 10 -- 1 There are no more than two different values among
9 17 1, 6, 8
10 11 -- 0 -- 9 Offline-evaluation.