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. win10家庭版安装Docker (Docker Toolbox)

    开启CPU的虚拟化功能(自行百度)之前安装了VM所以这部跳过.具体查看可以打开任务管理器->性能->cpu 查看是否有 虚拟化:已启用字样 下载Docker Toolbox  下载地址 h ...

  2. unsigned char bcd串乱码问题解决

    unsigned char bcd[13]; ...... string bcdstr; for(int i=0;i < 12;i++) { bcdstr=FormatString(" ...

  3. 红帽学习笔记[RHCSA] 第三课[输出重定向、Vi编辑器]

    第三课 关于Linux的输入输出 输入输出 0 stdin 标准输入 仅读取 1 stdout 标准输出 仅写入 2 stderr 标准错误 仅写入 3 filename 其他文件 读取和/或写入 输 ...

  4. P5020货币系统

    这个题是2018提高组真题,是一道看不出是背包的背包题. 题干特别长,甚至有些没看懂.题意为给出一组货币面值,然后从这里面用最少的面值数量取代原先的面值.比如3,6直接用3表示.一开始想到了小凯的疑惑 ...

  5. C++自学教程第一课——你好世界,我是柠檬鲸。

    C++系列教程现在在自己学校的一个博客平台发布,几个朋友一起搭建的 [C++基础教程系列](https://blog.ytmaxoj.org/cpp_basic_liuary-0/) 下面是原来的正文 ...

  6. Python 操作sqlite数据库及保存查询numpy类型数据(二)

    # -*- coding: utf-8 -*- ''' Created on 2019年3月6日 @author: Administrator ''' import sqlite3 import nu ...

  7. mysql使用MRG_MyISAM(MERGE)实现水平分表

    在MySQL中数据的优化尤其是大数据量的优化是一门很大的学问,当然其它数据库也是如此,即使你不是DBA,做为一名程序员掌握一些基本的优化信息,也可以让你在自己的程序开发中受益匪浅.当然数据库的优化有很 ...

  8. mysql分组函数及其用例

    功能:用作统计使用,又称为聚合函数或统计函数或组函数 分类:sum 求和.avg 平均值.max 最大值 .min 最小值 .count 计算个数 特点: 1.sum.avg一般用于处理数值型,max ...

  9. Qt带参数的信号和槽

    在Qt的开发过程中,信号带参数是很常见的,在使用带参数的信号槽时,有以下几点需要注意. 当信号和槽函数的参数数量相同时,它们的参数类型要完全一致. 信号和槽函数的声明: signals: void i ...

  10. ipsec概念理解

    互联网安全协议(英语:Internet Protocol Security,缩写:IPsec): 本质上一个协议包,透过对IP协议的分组进行加密和认证来保护IP协议的网络传输协议族(一些相互关联的协议 ...