B. The 67th 6-7 Integer Problem

time limit per test

1 second

memory limit per test

256 megabytes

So, Macaque has passed his first challenge (and is not acknowledging your help whatsoever). After all, it was only given to him so he could engage in his greatest pleasure --- crunching on desiccated freezedried hamburgers and yelling 'trivial' at the screen. However, he has another, much more important task ahead of him, and he has once again enlisted you to help him.

You are given 7 integers a1,a2,...,a7.

You must negate 6 out of the 7 integers (that is, multiply them by −1). Over all possible ways to negate 6 out of the 7 integers, find the maximum possible sum of a.

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤6767). The description of the test cases follows.

The first and only line of each test case contains 7 space-separated integers a1,a2,...,a7 (−67≤ai≤67).

Output

For each test case, output the maximum sum of a after negating 6 out of the 7 integers, on a new line.

Example

Input

Copy

复制代码

4

41 41 41 41 41 41 41

6 9 4 20 6 7 67

1 2 3 4 5 6 7

6 7 6 7 6 7 6

Output

Copy

复制代码

-205

15

-14

-31

Note

In the first test case, no matter which 6 integers we pick to negate, the maximum sum is −41−41−41−41−41−41+41=−205.

In the second test case, we can negate all integers except a7 to obtain a sum of −6−9−4−20−6−7+67=15.

解题说明:此题其实就是找出最大的那个数,然后其他数都变成相反数,最后求和。

cpp 复制代码
#include <stdio.h>

int main()
{
    int t;
    scanf("%d", &t);
    while (t--)
    {
        int a[7];
        int sum = 0, mx = -100;
        for (int i = 0; i < 7; i++)
        {
            scanf("%d", &a[i]);
            sum += a[i];
            if (a[i] > mx)
            {
                mx = a[i];
            }
        }
        int ans = 2 * mx - sum;
        printf("%d\n", ans);
    }
    return 0;
}
相关推荐
伊玛目的门徒2 小时前
试用leetcode之典中典 二数之和问题
java·算法·leetcode
Jerry2 小时前
LeetCode 226. 翻转二叉树
算法
想做小南娘,发现自己是女生喵4 小时前
【无标题】
数据结构·算法
Kx_Triumphs5 小时前
HDU4348 To the moon(主席树区间修改模板)
算法·题解
旖-旎6 小时前
《LeetCode647 回文子串 || LeetCode 5 最长回文子串》
c++·算法·leetcode·动态规划·哈希算法
轻颂呀7 小时前
约瑟夫环问题
算法
凤凰院凶涛QAQ8 小时前
《Java版数据结构 & 集合类剖析》栈与队列:“push/pop 是栈的灵魂,offer/poll 是队列的骨架——四组 API,两种人生”
java·开发语言·数据结构
科技大视界8 小时前
投资AI项目,传统尽调不够用了——李章虎律师拆解算法、数据、算力三大雷区
人工智能·算法·数据挖掘
郝学胜-神的一滴9 小时前
算法实战:最小k个数——大顶堆的优雅解法
开发语言·数据结构·c++·python·程序人生·算法·排序算法