题目链接:https://vjudge.net/contest/242578#problem/B

Dasha decided to bake a big and tasty layer cake. In order to do that she went shopping and bought n rectangular cake layers. The length and the width of the i-th cake layer were ai and bi respectively, while the height of each cake layer was equal to one.

From a cooking book Dasha learned that a cake must have a form of a rectangular parallelepiped constructed from cake layers of the same sizes.

Dasha decided to bake the biggest possible cake from the bought cake layers (possibly, using only some of them). It means that she wants the volume of the cake to be as big as possible. To reach this goal, Dasha can cut rectangular pieces out of the bought cake layers. She always cuts cake layers in such a way that cutting lines are parallel to the edges of that cake layer. Dasha isn't very good at geometry, so after cutting out a piece from the original cake layer, she throws away the remaining part of it. Also she can rotate a cake layer in the horizontal plane (swap its width and length).

Dasha wants her cake to be constructed as a stack of cake layers of the same sizes. Each layer of the resulting cake should be made out of only one cake layer (the original one or cut out from the original cake layer).

Help Dasha to calculate the maximum possible volume of the cake she can bake using given cake layers.

Input

The first line contains an integer n (1 ≤ n ≤ 4000) — the number of cake layers that Dasha can use.

Each of the following n lines contains two integer numbers ai and bi (1 ≤ ai, bi ≤ 106) — the length and the width of i-th cake layer respectively.

Output

The first line of the output should contain the maximum volume of cake that can be baked using given layers.

The second line of the output should contain the length and the width of the resulting cake. If there are many solutions with maximum possible volume, print any of them.

Examples

Input
5
5 12
1 1
4 6
6 4
4 6
Output
96
6 4
Input
2
100001 900000
900001 100000
Output
180000000000
900000 100000

Note

In the first example Dasha doesn't use the second cake layer. She cuts 4 × 6 rectangle from the first cake layer and she uses other cake layers as is.

In the second example Dasha cuts off slightly from the both cake layers.

题目大意:输入n,代表蛋糕有n层,接下来n行代表每层蛋糕的长度宽度,每层蛋糕的高度都是1 ,长宽可以交换位置,问你长宽取值为多少时,切得的蛋糕体积最大

个人思路:由题可知,长宽的取值一定在已有的长宽中得到,这题其实就是暴力,枚举每一个长和每一个宽,取最大的那个就是答案了

看代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
typedef long long ll;
using namespace std;
const ll mod=1e9+;
const int maxn=4e3+;
const int maxk=+;
const int maxx=1e4+;
const ll maxe=+;
#define INF 0x3f3f3f3f3f3f
struct cake
{
int w,l;
}a[maxn];
bool cmp(const cake a,const cake b)
{
return a.w<b.w;
}
int main()
{
ll n,ans=,answ,ansl;
int c[maxn];
cin>>n;
for(int i=;i<n;i++)
{
cin>>a[i].w>>a[i].l;
if(a[i].w>a[i].l)
swap(a[i].w,a[i].l);
}
sort(a,a+n,cmp);
for(int i=;i<n;i++)
{
int sum=;
for(int j=;j<n;j++)
{
if(a[j].l>=a[i].l)
{
c[sum++]=a[j].w;
}
}
for(int j=;j<sum;j++)
{
ll res;
res=(ll)a[i].l*c[j]*(sum-j);
if(res>ans)
{
ans=res;
answ=c[j];
ansl=a[i].l;
}
}
}
cout<<ans<<endl;
cout<<answ<<" "<<ansl<<endl;
return ;
}

CodeForces - 589B的更多相关文章

  1. CodeForces - 589B(暴力)

    题目链接:http://codeforces.com/problemset/problem/589/B 题目大意:告诉你n 个矩形,知道矩形的长度和宽度(长和宽可以互换),每个矩形的长度可以剪掉一部分 ...

  2. CodeForces 589B Layer Cake (暴力)

    题意:给定 n 个矩形是a*b的,问你把每一块都分成一样的,然后全放一块,高度都是1,体积最大是多少. 析:这个题,当时并没有完全读懂题意,而且也不怎么会做,没想到就是一个暴力,先排序,先从大的开始选 ...

  3. CodeForces - 589B(暴力+排序)

    Dasha decided to bake a big and tasty layer cake. In order to do that she went shopping and bought n ...

  4. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  5. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  6. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  7. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  8. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  9. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

随机推荐

  1. TVYJ1266:费解的开关

    我对状态空间的理解:https://www.cnblogs.com/AKMer/p/9622590.html 题目传送门:http://www.joyoi.cn/problem/tyvj-1266 这 ...

  2. hdu 5909 Tree Cutting —— 点分治

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5909 点分治,每次的 rt 是必选的点: 考虑必须选根的一个连通块,可以DP,决策就是在每个子树中决定选不 ...

  3. 问题7:如何实现用户的历史记录功能(最多n条)

    实例:制作猜字游戏,添加历史记录功能,显示用户最近猜过的数字 解决方案:使用容量为n的队列存储历史记录 使用标准库colections中的deque,一个双端循环队列 程序退出前,可以使用pickle ...

  4. MySQL Sending data导致查询很慢的问题详细分析

    这两天帮忙定位一个MySQL查询很慢的问题,定位过程综合各种方法.理论.工具,很有代表性,分享给大家作为新年礼物:) [问题现象] 使用sphinx支持倒排索引,但sphinx从mysql查询源数据的 ...

  5. 在浏览器中输入url并回车后发生了什么?

    1 解析url url主要由以下几个部分组成: 1 传输协议 2 服务器 3 域名 4 端口 5 虚拟目录 6 文件名 7 锚 8 参数 2 DNS(域名)解析 找到域名对应的ip 3 浏览器与网站建 ...

  6. Myeclipse如何使用Maven添加jar包

    很多新手都不知道如何在maven项目里添加jar包. 以前我还没接触maven的时候下载过一个demo,是maven项目. 我居然是照着他的pom.xml文件一个一个的写!!! 很多人认为理所当然的东 ...

  7. js数组中的reverse()方法

    reverse方法是将数组中的元素的顺序进行反转,在原数组上操作,然后返回原数组.由于本人是学习js的新人,对reverse函数进行了几个小实验,以下实验均在Chrome浏览器上运行 实验一:reve ...

  8. js刷新页面方法大全(转)

    刷新页面实现方式总结(HTML,ASP,JS) 转载  2008-11-13   作者:    我要评论 多种方法实现页面的刷新代码 定时刷新: 1,<script>setTimeout( ...

  9. C++类中的常数据成员和静态数据成员的区别

    刚开始学习C++的类和对象的部分,对类中的常数据成员和静态数据成员的概念和用法经常混淆,所以今天整理一下,顺便说一下,今天是我的生日,祝我生日快乐,呵呵. 常数据成员 常数据成员是指在类中定义的不能修 ...

  10. macos上改变输入法顺序

    设置界面上是不能拖放顺序的,唯一解决办法是: 一.先选择所有文档使用相同输入源 二.选择用美国英语 三.再选择允许多个输入源,再打开原来的中文输入法 顺序就调过来了!尼玛,这就是苹果的人性化?懒得吐嘈 ...