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. centos7 VM虚拟机在主机关机重启后,无法ping通

    解决办法 1.虚拟机的某些网络相关的服务没有启动,打开电脑的服务启动相关服务 2.打开虚拟机的虚拟网络设置,恢复默认设置即可 3.判定虚拟网卡的网关和centos的网关是否一致,如果不一致,改成一致, ...

  2. python可视化:matplotlib系列

    matplotlib 的官方文档: https://matplotlib.org/users/index.html 1 子图布局管理 布局参数 紧密布局的方法 坐标轴的公用和隐藏 2 直方图bar和b ...

  3. 剑指Offer编程题(Java实现)——复杂链表的复制

    题目描述 输入一个复杂链表(每个节点中有节点值,以及两个指针,一个指向下一个节点,另一个特殊指针指向任意一个节点),返回结果为复制后复杂链表的head.(注意,输出结果中请不要返回参数中的节点引用,否 ...

  4. SQL如何通过当前日期获取上周一日期【转】

    --当前时间 select getdate() --当前时间周的起始日期(以周一为例) ,) --上周起始: ,,)) --上上周起始: ,,)) --上上上周起始:s elect ,,))

  5. tz汇报

    不爽,不满意,存在太多Bug,汇报前的了解不充分,了解到了有那些领导参加,但是没有具体了解领导的时间安排,没有按照领导的时间调整汇报提纲及思路,汇报到1个半小时,领导需要参加会议,提前离开,没能够与领 ...

  6. java 数组详细介绍

    一.概述 数组(Array),是多个相同类型数据按一定顺序排列的集合,并使用一个名字命名,并通过编号的方式对这些数据进行统一管理 数组常见概念: 数组名, 下标(或索引), 元素, 数组的长度 数组本 ...

  7. P-残缺的棋盘

    Input 输入包含不超过10000 组数据.每组数据包含6个整数r1, c1, r2, c2, r3, c3 (1<=r1, c1, r2, c2, r3, c3<=8). 三个格子A, ...

  8. 数组和datatable间的相互转换[C#]

    byte[] LogMsgByte = null; DataTable dtMessageInfo = new DataTable(); //将datatable转换为数组 dtMessageInfo ...

  9. Linux下配置JDK环境

    安装前需要查询Linux中是否已经存在jdk 如果存在,将存在的jdk删除 在/etc/profile中添加以下 JAVA_HOME为jdk的安装目录 PATH为jdk可执行文件的目录 使用sourc ...

  10. Springboot 打jar包项目无法访问jsp问题解决方案

    maven编译插件,请选择1.4.2.RELEASE版本,1.5.x的版本已经不再支持 pom.xml重要部分如下: <build> <resources> <resou ...