Description

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.

Sample Input

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

Hint

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个高度为1的蛋糕,分别有长和宽; 让你将这些蛋糕垒起来平行于边切,使得每块蛋糕长宽相同;求最大体积,输出体积和长、宽;

思路:输入时统一长和宽(宽小于长),然后按照宽从小到大排序,两重循环,i=0~n-1,j=0~n-1,计数vec[0~j].second>=ves[i].second有多少,

记为num,mp[i][j]=num,由此可以看出mp[i][j]表示,以ves[i].second为宽,以ves[j].first为长的蛋糕层的个数,那么以ves[i].second为宽,以ves[j].first为长的蛋糕的体积最大为;ves[i].second*ves[j].first*mp[i][j];最后两层循环遍历,计算以每个mp[i][j]为蛋糕大小的体积,找出最大值;

代码如下:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int maxn=;
typedef long long LL;
int mp[maxn][maxn];
int main()
{
int n;
LL x,y;
while(cin>>n)
{
memset(mp, , sizeof(mp));
vector< pair<LL ,LL> >vec;
for(int i=; i<n; i++)
{
cin>>x>>y;
if(x>y) swap(x, y);
vec.push_back(make_pair(x, y));
}
sort(vec.begin(), vec.end());
for(int i=n-; i>=; i--)
{
int num=;
for(int j=n-;j>=;j--)
{
if(vec[j].second>=vec[i].second)
num++;
mp[i][j]=num;
}
}
LL ans=,ansx=,ansy=;
for(int i=; i<n; i++)
{
for(int j=; j<n; j++)
{
LL x=vec[i].first;
LL y =vec[j].second;
LL sum=x*y;
LL tot=sum*mp[j][i];
if(ans < tot)
{
ans=tot;
ansx=x;
ansy=y;
}
}
}
cout<<ans<<endl;
cout<<ansx<<" "<<ansy<<endl;
}
return ;
}

2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest, B. Layer Cake的更多相关文章

  1. 2018-2019 ICPC, NEERC, Southern Subregional Contest

    目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...

  2. Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest

    2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...

  3. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution

    从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...

  4. Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结

    第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...

  5. codeforce1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 题解

    秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...

  6. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)

    A. Find a Number 找到一个树,可以被d整除,且数字和为s 记忆化搜索 static class S{ int mod,s; String str; public S(int mod, ...

  7. 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)

    i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...

  8. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) Solution

    A. Find a Number Solved By 2017212212083 题意:$找一个最小的n使得n % d == 0 并且 n 的每一位数字加起来之和为s$ 思路: 定义一个二元组$< ...

  9. 【*2000】【2018-2019 ICPC, NEERC, Southern Subregional Contest C 】Cloud Computing

    [链接] 我是链接,点我呀:) [题意] [题解] 我们可以很容易知道区间的每个位置有哪些安排可以用. 显然 我们优先用那些花费的钱比较少的租用cpu方案. 但一个方案可供租用的cpu有限. 我们可以 ...

随机推荐

  1. openwrt 编译newifi 应用程序

    首先找交叉编译工具( toolchain ) Development Snapshots http://downloads.openwrt.org/snapshots/trunk/ 我需要的版本是 m ...

  2. sizeof()用法汇总

    sizeof()功能:计算数据空间的字节数 1.与strlen()比较      strlen()计算字符数组的字符数,以"\0"为结束判断,不计算为'\0'的数组元素.      ...

  3. LeetCode:5_Longest Palindromic Substring | 最长的回文子串 | Medium

    题目: Given a , and there exists one unique longest palindromic substring. 解题思路:1.简单思路:暴力破解法,时间复杂度O(n^ ...

  4. android studio ndk使用openMP

    好久没碰ndk了,之前都是在eclipse下写makefile配置c++程序的,现在发现主流都是用android studio,eclipse俨然已经被遗弃了,正好最近项目需要用openMP做算法加速 ...

  5. IT项目经理成长手记

    1.流程化,项目化,工业化: 2.启动,规划,实施,监控,收尾.五个过程 3.需求管理,项目策划,项目监控,集成项目管理,定量项目管理,供应商协议管理,风险管理. 4.项目经理是熬出来的,伟大都是熬出 ...

  6. rm: 无法删除&quot;/run/user/root/gvfs&quot;: 是一个目录 问题

    2013-03-02    bxd@linux:~$ sudo su [sudo] password for bxd:  root@linux:/home/bxd# exit exit rm: 无法删 ...

  7. struts2 using kindeditor upload pictures (including jmagic compressed images)

    Project uses a kindeditor3.4 UploadContentImgAction @SuppressWarnings("serial") @ParentPac ...

  8. CSS3实现倒计时

    CSS3实现倒计时小程序,界面如下: 代码如下: <style> body,html{ margin:0px; height:100%; } body{background: #000; ...

  9. 破解android手机图形锁

    安卓手机的图形锁包括3*3,4*4,5*5的点阵,按次序连接数个点从而达到锁定/解锁的功能.以3*3为例,最少需要连接4个点,最多能连接9个点.在我们进行绘制图形的过程中,每选中这9个点中的一个点,实 ...

  10. 互联网金融必须知道:O2O、P2P、MRD、BRD、LBS、PV、UV、KPI、MRD、VP、UED....

    进入互联网的朋友们和身为互联网业内人士,你们知道有多少专业术吗?有时候专业术语也是一种逼格.商业需求文档,市场需求文档,产品需求文档,功能详细说明文档,华丽丽的各种文档你知道吗?用户体验,用户界面,用 ...