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;
}
相关推荐
kisshyshy4 小时前
🍦 雪糕、食堂、火车厢:三幅漫画吃透栈、队列与链表
javascript·算法
猿人谷11 小时前
不只是 CPU 阈值:STAR 如何用 GAT + Transformer 做容器级自动扩缩容?
人工智能·算法
复杂网络13 小时前
Stable Diffusion 视觉大模型微调技术深度调研
算法
复杂网络13 小时前
基于 Stable Diffusion 架构的视觉大模型代表性工作与原理深度解析
算法
MrZhao40013 小时前
Agent Loop 如何用 Hook 扩展:权限、日志与工具拦截
算法
MrZhao40013 小时前
Agent 为什么需要 Skills:别把所有知识都塞进 system prompt
算法
JieE2122 天前
LeetCode 101. 对称二叉树|JS 递归 + 迭代双解法,彻底搞懂镜像判断
javascript·算法
JieE2123 天前
LeetCode 56. 合并区间|超清晰 JS 图解思路,面试高频区间题
javascript·算法·面试
Jack203 天前
HarmonyOS开发中错误处理策略:网络异常统一处理
算法
小小杨树3 天前
读懂色彩:拍照调色不再难
算法·计算机视觉·配色