ACM-ICPC 2017 Asia Urumqi B. The Difference

Alice was always good at math. Her only weak points were multiplication and subtraction. To help her with that, Bob presented her with the following problem.

He gave her four positive integers. Alice can change their order optionally. Her task is to find an order, denoted by A_1,A_2,A_3A1​,A2​,A3​ and A_4A4​, with the maximum value of A_1 \times A_2 - A_3 \times A_4A1​×A2​−A3​×A4​.

Input

The input contains several test cases and the first line provides an integer t (1 \le t \le 100)t(1≤t≤100) indicating the number of cases.

Each of the following t lines contains four space-separated integers.

All integers are positive and not greater than 100100.

Output

For each test case, output a line with a single integer, the maximum value of A_1 \times A_2 - A_3 \times A_4A1​×A2​−A3​×A4​.

样例输入

5
1 2 3 4
2 2 2 2
7 4 3 8
100 99 98 97
100 100 1 2

样例输出

10
0
44
394
9998

 

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
int main(){
	int t;
	cin>>t;
	for(int i=0;i<t;i++){
		int a[4];
		for(int j=0;j<4;j++) scanf("%d",&a[j]);
		sort(a,a+4);
		printf("%d\n",a[3]*a[2]-a[0]*a[1]);
	}
	return 0;
}

欢迎大家加入 早起学习群,一起学习一起进步!(群号:642179511)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值