Layer Cake
time limit per test

6 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

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 wereai 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 test(s)
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.

题意:在给定蛋糕数量和长宽信息时,任取面包数量,让面包堆积成平行六边形即每一个面包的长和宽都相等(多了可以裁,求体积的最大值,每个面包的高度是1.

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm> using namespace std; #define maxn 4010 struct node
{
int x, y;
}P[maxn]; int X[maxn], Y[maxn]; int cmp(node a, node b)
{
if(a.x == b.x)
return a.y < b.y;
return a.x > b.x;
} int main()
{
int n, x, y, p, q; while(scanf("%d", &n) != EOF)
{
long long ans, sum = 0;
for(int i = 0; i < n; i++)
{
scanf("%d%d", &x, &y);
P[i].x = min(x, y);
P[i].y = max(x, y);
}
sort(P, P+n, cmp);
for(int i = 0; i < n; i++)
X[i] = P[i].x, Y[i] = P[i].y;
for(int i = 0; i < n; i++)
{
sort(Y, Y+i+1);
for(int j = 0; j <= i; j++)
{
ans = (long long)X[i] * Y[j] * (i-j+1);
if(ans > sum)
{
sum = ans;
p = X[i];
q = Y[j];
}
}
}
printf("%I64d\n%d %d\n", sum, p, q);
}
return 0;
}

  

Layer Cake cf的更多相关文章

  1. 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest, B. Layer Cake

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

  2. #7 div2 B Layer Cake 造蛋糕 智商题+1

    B - Layer Cake Time Limit:6000MS     Memory Limit:524288KB     64bit IO Format:%I64d & %I64u Sub ...

  3. CodeForces 589B Layer Cake (暴力)

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

  4. 【转载】ACM总结——dp专辑

    感谢博主——      http://blog.csdn.net/cc_again?viewmode=list       ----------  Accagain  2014年5月15日 动态规划一 ...

  5. 【DP专辑】ACM动态规划总结

    转载请注明出处,谢谢.   http://blog.csdn.net/cc_again?viewmode=list          ----------  Accagain  2014年5月15日 ...

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

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

  7. dp专题训练

    ****************************************************************************************** 动态规划 专题训练 ...

  8. 你真的了解分层架构吗?——写给被PetShop"毒害"的朋友们

    一叶障目 .NET平台上的分层架构(很多朋友称其为“三层架构”),似乎是一个长盛不衰的话题.经常看到许多朋友对其进行分析.探讨.辩论甚至是抨击.笔者在仔细阅读了大量这方面文章后,认为许多朋友在分层架构 ...

  9. 【DP专辑】ACM动态规划总结(转)

    http://blog.csdn.net/cc_again/article/details/25866971 动态规划一直是ACM竞赛中的重点,同时又是难点,因为该算法时间效率高,代码量少,多元性强, ...

随机推荐

  1. SVN服务器和客户端使用教程总结

    一.SVN简介 Subversion是什么? 它是一个自由/开源的版本控制系统,一组文件存放在中心版本库,记录每一次文件和目录的修改,Subversion允许把数据恢复到早期版本,或是检查数据修改的历 ...

  2. [Git] 020 stash —— Git 中的”皮姆粒子“

    0. 我准备模拟两种情况 第一种 第二种 情况简析 仓库中的最新版本发现 Bug,需要立即修复 当前在 "dev" 分支中工作到一定程度,尚不能提交,但删之可惜 ps: 在分支中没 ...

  3. [转帖]华为海思Hi1620芯片发布在即 7nm制程ARM架构最高可达3.0GHz

    华为海思Hi1620芯片发布在即 7nm制程ARM架构最高可达3.0GHz https://www.cnbeta.com/articles/tech/850561.htm 中电科旗下的普华软件 支持国 ...

  4. BindWeb - Bind智能DNS管理系统介绍

    2019-05-08 演示网站: https://bindw.cdneks.com demo/demo 2018-11-27 修改部署架构,取消网络共享存储设备,在每台BIND服务器启用NFS4并仅向 ...

  5. 安装CentOS7虚拟机

    基础环境 Windows 10 VMware Workstation 1.下载CentOS7镜像 https://www.centos.org/download/ 此次安装使用的版本为: CentOS ...

  6. vue点击除了某组件本身的其它地方, 隐藏该组件的方法

    点击emoji表情标签, 出现标签组件,点击其它地方, 改组件消失的效果; <template> <div class="writeZoon"> <d ...

  7. 极*Java速成教程 - (7)

    Java高级特性 数组 在Java中,数组是一串连续的,不可改变长度的,对象被固定的,类型固定的连续空间.数组中的随机访问非常迅速,但为了速度放弃了灵活性.而效率也是数组最大的优点. 在使用泛型的容器 ...

  8. java中Map的put函数和get函数用法

    ---内容开始--- 没有比较完整的说明他们的用法,一般就只能看源函数,但是看起来比较的费劲. 那么究竟put函数和get函数的用法是如何的呢? 当然java中的Map集合是有Key和Value的. ...

  9. soot学习历程---(1)

    今天看了soot生成手册的部分内容,简单摘录一下 Scene 表示分析所处的完整环境,可以借此设置application class(用sootclass),主类(main),point-to和cal ...

  10. Kotlin学习(5)类型系统

    可空性(避免空指针异常) /* *这个函数的参数代表传入一个String类型变量的实例,这代表它不可以为空 */ fun a(str:String){ println(str) } //这样调用a() ...