C. Magical Boxes

Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.

From the top view each magical box looks like a square with side length equal to 2k (k is an integer, k ≥ 0) units. A magical box v can be put inside a magical box u, if side length of v is strictly less than the side length of u. In particular, Emuskald can put 4 boxes of side length 2k - 1 into one box of side length 2k, or as in the following figure:

Emuskald is about to go on tour performing around the world, and needs to pack his magical boxes for the trip. He has decided that the best way to pack them would be inside another magical box, but magical boxes are quite expensive to make. Help him find the smallest magical box that can fit all his boxes.

Input

The first line of input contains an integer n (1 ≤ n ≤ 105), the number of different sizes of boxes Emuskald has. Each of following n lines contains two integers ki and ai (0 ≤ ki ≤ 109, 1 ≤ ai ≤ 109), which means that Emuskald has ai boxes with side length 2ki. It is guaranteed that all of ki are distinct.

Output

Output a single integer p, such that the smallest magical box that can contain all of Emuskald’s boxes has side length 2p.

Examples

input

2
0 3
1 5

output

3

input

1
0 4

output

1

input

2
1 10
2 2

output

3

Note

Picture explanation. If we have 3 boxes with side length 2 and 5 boxes with side length 1, then we can put all these boxes inside a box with side length 4, for example, as shown in the picture.

In the second test case, we can put all four small boxes into a box with side length 2.

题目大意:

问用多大边长的正方形盒子,才能够能够装下所有给出的盒子

其中,如果一个盒子的边长大于另一个盒子,那么这个盒子就能够容纳那另一个盒子 。

思路:

我们先将盒子按照从小到大排序,那么对于临近的两个大小的盒子,我们考虑将小盒子放在大盒子中, 如果容纳不下,那么就相当于再多开几个大盒子。用这个贪心的思想,最后放完之后,还剩多少盒子,即外层盒子。

#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<math.h>
using namespace std;
#define LL long long
#define MAXN 100100
struct node
{
LL x;
LL y;
} a[MAXN*2];
bool cmp(node u,node v)
{
return u.x<v.x;
}
int main()
{
LL n,i,j;
cin>>n;
for(i=1; i<=n; i++)
cin>>a[i].x>>a[i].y;
sort(a+1,a+n+1,cmp);
LL k=a[1].x,l=a[1].y;
for(i=2; i<=n; i++)
{
if(a[i].x==k)
l=l+a[i].y;
else
{
LL b=a[i].x-k;
for(j=1; j<=b; j++)
{
if(l%4==0)
l=l/4;
else
l=(l/4)+1;
if(l==1)
break;
}
k=a[i].x,l=max(l,a[i].y);
}
}
while(1)
{
if(l==1)
break;
if(l%4==0)
l=l/4;
else
l=(l/4)+1;
k++;
}
if(k==a[n].x)
cout<<k+1;
else
cout<<k;
return 0;
}

codeforce 270C Magical Boxes的更多相关文章

  1. Codeforces Round #165 (Div. 2)

    C. Magical Boxes 问题相当于求\[2^p \gt \max{a_i \cdot 2^{k_i}},p \gt k_i\] D. Greenhouse Effect \(dp(i,j)\ ...

  2. codeforce C. Okabe and Boxes

    题目传送门 这道题 每次删除一个点 那么这个点必然在栈里面 那么如果堆顶不是他 我们就需要一次操作使得堆合理 这时我们可以把他删除然后把他下面的点打个标记表示这下面的点以后想怎么排就怎么排以后都不需要 ...

  3. Magical平台类库代码分享

    这些天闲来无事,就整理了一些类库.jQuery插件和自定义控件.今天和大家分享下Magical平台类库代码. 下图为整个解决方案图.MagicalPlatForm里面定义的是众多的Layer层:Mag ...

  4. Fedora 24 Gnome Boxes 无法ping通网络

    安装Fedora 24在试用虚拟机时发现无法ping通外网. 我傻傻地以为是软件问题. 问题描述: 尝试ping程序来测试网络连通性: (我之前也是ping百度,后来在为了少打字百度了一些比较短的域名 ...

  5. STL : map函数的运用 --- hdu 4941 : Magical Forest

    Magical Forest Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

  6. hdu4941 Magical Forest (stl map)

    2014多校7最水的题   Magical Forest Magical Forest Time Limit: 24000/12000 MS (Java/Others)    Memory Limit ...

  7. Problem B Boxes in a Line

     省赛B题....手写链表..其实很简单的.... 比赛时太急了,各种手残....没搞出来....要不然就有金了...注:对相邻的元素需要特判..... Problem B Boxes in a Li ...

  8. Codeforces Round #229 (Div. 2) C. Inna and Candy Boxes 树状数组s

    C. Inna and Candy Boxes   Inna loves sweets very much. She has n closed present boxes lines up in a ...

  9. Open judge C16H:Magical Balls 快速幂+逆元

    C16H:Magical Balls 总时间限制:  1000ms 内存限制:  262144kB 描述 Wenwen has a magical ball. When put on an infin ...

随机推荐

  1. 2017蓝桥杯算式900(C++C组)

    题目:算式900 小明的作业本上有道思考题:  看下面的算式:  (□□□□-□□□□)*□□=900  其中的小方块代表0~9的数字,这10个方块刚好包含了0~9中的所有数字.  注意:0不能作为某 ...

  2. TP基础

    一.目录结构 解压缩到web目录下面,可以看到初始的目录结构如下: www WEB部署目录(或者子目录)├─index.php 入口文件├─README.md README文件├─Applicatio ...

  3. 绕过XSS过滤姿势总结

    0x01 弹窗关键字检测绕过 基本WAF都针对常用的弹窗函数做了拦截,如alert().prompt().confirm(),另外还有代码执行函数eval(),想要绕过去也比较简单,我们以alert( ...

  4. three.js中让模型自动居中的代码如下:

    //load_Model为需要居中的3D模型 //原理是通过boundingBoxHelper 来计算模型的大小范围 var hex = 0xff0000; var MD_Length,MD_Widt ...

  5. C#_关键字:Lock的解释和使用

    定义 lock关键字,互斥锁,通过锁住某一对象从而将语句块({})里面的代码设置为临界区. 线程在线性执行代码时若遇到互斥锁,必须先申请互斥锁的访问权,若访问成功,则继续线性访问互斥锁后的临界区代码块 ...

  6. 读写SQL脚本进行创建表、视图和存储过程

    一.按照先创建表.视图.存储过程的顺序创建: 二.导出脚本的时候注意:保存为ANSI文本,选项中:if not exists为true,防止覆盖:包含说明性标头为false;use database为 ...

  7. C. Primes and Multiplication

    题目连接:https://codeforces.com/contest/1228/problem/C 题目大意:g(x,y)==y^k(其中y^k是X的最大可以整除因子) f(x,y)==g(x,p1 ...

  8. Mark down 使用总结

    Markdown语法 Markdown是一种纯文本.轻量级的标记语言,通过简单的标记,就可以使文本具有一定的格式,操作简单.使用广泛,常见的比如github上的README.md . Markdown ...

  9. C#开发BIMFACE系列32 服务端API之模型对比3:批量获取模型对比状态

    系列目录     [已更新最新开发文章,点击查看详细] 在<C#开发BIMFACE系列31 服务端API之模型对比2:获取模型对比状态>中介绍了根据对比ID,获取一笔记录的对比状态.由于模 ...

  10. Java中集合的嵌套

    集合的嵌套遍历 获取10个1-20之间的随机数,要求不能重复 键盘录入多个数据,以0结束,要求在控制台输出这多个数据的最大值. public static void main(String[] arg ...