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;
}
相关推荐
灵枢时代14 分钟前
小程序在生鲜配送行业,如何设计夜间预约和次日达的订单处理流程?
数据结构·人工智能·小程序
June`15 分钟前
常量内存和只读缓存
c++·人工智能·算法·cuda
一条大祥脚17 分钟前
ABC468 扫描线|贡献法|二阶差分|线段树优化DP
数据结构·算法
happyprince21 分钟前
篇2-bitsandbytes-具体观-算法与实现剖析
算法
普通攻击往后拉10 小时前
Leetcode 206. 反转链表
算法·leetcode·链表
@syh.11 小时前
【贪心】矩阵消除游戏
算法·游戏·矩阵
可编程芯片开发11 小时前
基于零极点配置的PID控制系统simulink建模与仿真
算法
徐小夕12 小时前
开源!我用SQLite + DuckDB打造了一款可视化AI问数平台
前端·算法·github
Hrain-AI12 小时前
2026 企业 AI 智能体平台横评:8 大主流平台 7 维度实测对比
人工智能·算法·机器学习