2019-2020 ICPC, Asia Jakarta Regional Contest H. Twin Buildings

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

As you might already know, space has always been a problem in ICPC Jakarta. To cope with this, ICPC Jakarta is planning to build two new buildings. These buildings should have a shape of a rectangle of the same size. Now, their problem is to find land to build the buildings.

There are NN lands available for sale. The ithith land has a rectangular shape of size Li×WiLi×Wi. For a good feng shui, the building's side should be parallel to the land's sides.

One way is to build the two buildings on two different lands, one on each land (not necessarily with the same orientation). A building of size A×BA×B can be build on the ithith land if and only if at least one of the following is satisfied:

  • A≤LiA≤Li and B≤WiB≤Wi, or
  • A≤WiA≤Wi and B≤LiB≤Li.

Alternatively, it is also possible to build two buildings of A×BA×B on the ithith land with the same orientation. Formally, it is possible to build two buildings of A×BA×B on the ithith land if and only if at least one of the following is satisfied:

  • A×2≤LiA×2≤Li and B≤WiB≤Wi, or
  • A×2≤WiA×2≤Wi and B≤LiB≤Li, or
  • A≤LiA≤Li and B×2≤WiB×2≤Wi, or
  • A≤WiA≤Wi and B×2≤LiB×2≤Li.

Your task in this problem is to help ICPC Jakarta to figure out the largest possible buildings they can build given NN available lands. Note that ICPC Jakarta has to build two buildings of A×BA×B; output the largest possible for A×BA×B.

Input

Input begins with a line containing an integer: NN (1≤N≤1000001≤N≤100000) representing the number of available lands. The next NN lines each contains two integers: LiLi WiWi (1≤Li,Wi≤1091≤Li,Wi≤109) representing the size of the land.

Output

Output in a line a number representing the largest building that ICPC Jakarta can build with exactly one decimal point (see sample input/output for clarity).

Examples

input

Copy

2
5 5
3 4

output

Copy

12.5

input

Copy

2
2 5
4 3

output

Copy

8.0

input

Copy

3
10 1
9 8
7 6

output

Copy

42.0

Note

Explanation for the sample input/output #1

Two buildings of 2.5×52.5×5 can be built both on the first land.

Explanation for the sample input/output #2

Two buildings of 2×42×4 can be built each on the first and second lands.

Explanation for the sample input/output #3

Two buildings of 7×67×6 can be built each on the second and third lands.

题意:

现在有n个矩形区域, 你需要建造两个大小为A×B的矩阵要求面积最大,有两种建造方式

两个建到同一个矩阵区域内, 或者分别建在两个矩阵区域内。

思路:

如果建在一个矩阵内, 比较简单就是n个区域每个区域的面积除以2

如果分别建在两个矩阵内, 那么我们设这n个矩阵的长为x, 宽为y

然后按照y降序排列, 因为以当前的y为宽, 那么之前的矩阵肯定都

可以达宽度y, 这样我们每次取当前的x跟前面最大的x取个min, 此

时的宽就是当前的y, 然后乘一下取个max就可以了。为了避免精损

使用longlong计算, 输出时候判下就可以了。

#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

#ifdef LOCAL
#define debug(x) cout << "[" __FUNCTION__ ": " #x " = " << (x) << "]\n"
#define TIME cout << "RuningTime: " << clock() << "ms\n", 0
#else
#define TIME 0
#endif
#define hash_ 1000000009
#define Continue(x) { x; continue; }
#define Break(x) { x; break; }
const int mod = 1e9 + 7;
const int N = 2e5 + 100;
struct node
{
	ll x, y;
	bool operator < (const node &oth)const
	{
		return y > oth.y;
	}
}a[N];
int main()
{
#ifdef LOCAL
	freopen("D:/input.txt", "r", stdin);
#endif
	int n;
	cin >> n;
	ll ans = 0;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i].x >> a[i].y;
		ans = max(ans, a[i].x * a[i].y);
		if (a[i].x > a[i].y)
			swap(a[i].x, a[i].y);
	}
	sort(a + 1, a + n + 1);
	ll MX = 0;
	for (int i = 1; i <= n; i++)
	{
		ans = max(ans, min(MX, a[i].x) * a[i].y * 2);
		MX = max(MX, a[i].x);
	}
	if (ans % 2)
		printf("%lld.5\n", ans / 2);
	else
		printf("%lld.0\n", ans / 2);
	return TIME;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值