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

 

你可能感兴趣的:(贪心)