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;
}
相关推荐
用户987409238871 小时前
llamafactory 0.6.3 没有 llamafactory-cli
算法
计算机安禾1 小时前
【算法分析与设计】第26篇:参数化算法与固定参数可解性理论
大数据·人工智能·算法·机器学习·剪枝
AI科技星2 小时前
基于**v=c(空间光速螺旋运动)唯一第一性原理**重新完整求导证明
人工智能·线性代数·算法·机器学习·架构·概率论·学习方法
风筝在晴天搁浅2 小时前
美团 LeetCode 692.前K个高频单词
算法·leetcode·职场和发展
地平线开发者2 小时前
量化训练时 fusebn/withbn 简介
算法·自动驾驶
不做无法实现的梦~2 小时前
MAVLink 协议教程
linux·stm32·嵌入式硬件·算法
墨白曦煜3 小时前
算法实战笔记:剥开回溯算法的外衣——从通用模板到高阶去重(八)
笔记·算法
z200509303 小时前
今日算法(回溯子集)(模版题)
数据结构·算法·leetcode
吴佳浩3 小时前
Vibe Coding 时代,研发经理为何越来越值钱?
算法·架构
IronMurphy3 小时前
【算法五十四】72. 编辑距离
算法