D - Four Segments

Monocarp wants to draw four line segments on a sheet of paper. He wants the ii-th segment to have its length equal to aiai (1≤i≤41≤i≤4). These segments can intersect with each other, and each segment should be either horizontal or vertical.

Monocarp wants to draw the segments in such a way that they enclose a rectangular space, and the area of that rectangular space should be maximum possible.

For example, if Monocarp wants to draw four segments with lengths 11, 22, 33 and 44, he can do it the following way:
在这里插入图片描述

Here, Monocarp has drawn segments ABAB (with length 11), CDCD (with length 22), BCBC (with length 33) and EFEF (with length 44). He got a rectangle ABCFABCF with area equal to 33 that is enclosed by the segments.
Calculate the maximum area of a rectangle Monocarp can enclose with four segments.

Input
The first line contains one integer tt (1≤t≤3⋅1041≤t≤3⋅104) — the number of test cases.

Each test case consists of a single line containing four integers a1a1, a2a2, a3a3, a4a4 (1≤ai≤1041≤ai≤104) — the lengths of the segments Monocarp wants to draw.

Output
For each test case, print one integer — the maximum area of a rectangle Monocarp can enclose with four segments (it can be shown that the answer is always an integer).

Example
Input
4
1 2 3 4
5 5 5 5
3 1 4 1
100 20 20 100
Output
3
25
3
2000
Note
The first test case of the example is described in the statement.

For the second test case, Monocarp can draw the segments ABAB, BCBC, CDCD and DADA as follows:
在这里插入图片描述

Here, Monocarp has drawn segments ABAB (with length 55), BCBC (with length 55), CDCD (with length 55) and DADA (with length 55). He got a rectangle ABCDABCD with area equal to 2525 that is enclosed by the segments.

#include <stdio.h>
int main()
{
   int n,m,t,a[100],k,i,j,c,b,d;
   scanf("%d",&m); 
   while(~scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3]))
   {
   	
   	for(i=0;i<3;i++)
   	{
   		for(j=0;j<3-i;j++)
   		{
   			if(a[j]>=a[j+1])
   			{
   				t=a[j];
   				a[j]=a[j+1];
   				a[j+1]=t;
			}
		}
	}
	
   	printf("%d\n",a[0]*a[2]);
   } 
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值