logo AlgoBeat OnlineJudge
登录 注册

#215695. [2019 KAIST RUN Spring] Water Knows the Answer

内存限制:1024 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Donghyun lives in 2D plane, having -axis as ground. It rains a lot in 2D plane, and the rain falls from .

Recently, Donghyun read a book called "Water Knows the Answer", and got impressed by the book. He now believes that he will be super intelligent and smart if he has water with him.

:::align{center}

The book "Water Knows the Answer" :::

Donghyun has rectangular boxes with (possibly) different heights and widths. He is going to rearrange those boxes in order to collect the rainfall. Then, the water will give him the answer. To achieve this, he have to place the box in a row. The ground absorbs the rainfall, so no empty space is allowed between the boxes. He may rotate some of the boxes or not, but he should make its edges parallel to the ground.

The water can flow to left or right, until it has space to flow. Formally, water in certain point can stay in its place if that point is not inside the box and has a box both somewhere to its left and somewhere to its right at the same height.

Donghyun wants to know the maximum area of water he can store. (In 2D plane, area means volume.) But, he doesn't have water yet, so he doesn't know the answer. Do you know the answer?

输入格式

The first line contains an integer , the number of boxes. ()

For the next lines, -th line contains two integer and , the width and height of -th box. ()

输出格式

Print a single integer, denoting the maximum area of water you can store if you arrange the boxes optimally.

样例

样例输入 1

3
4 3
2 6
5 1

样例输出 1

15

数据范围与提示

:::align{center}

Best arrangement for example input. :::