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;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章