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. go 基础安装

    一.安装: 1.下载GO的地址:https://golang.org/dl/ 点击安装包进行安装(linux直接解压) 设置环境变量(linux) 1. export GOROOT=$PATH:/pa ...

  2. ListView + ArrayAdapter + 接口回调

    众所周知,ListView是安卓最为频繁使用的控件,但是,随着人们审美观的提高,一些初级的ListView已经满足不了需求了,于是,我们必须为自己定制一套专属的ListView,这就需要用到适配器,A ...

  3. "二号标题"组件:<h2> —— 快应用组件库H-UI

     <import name="h2" src="../Common/ui/h-ui/text/c_h2"></import> < ...

  4. Git中rebase失败了如何进行恢复

    rebase失败后的恢复 记一次翻车现场 记一次翻车的现场,很早之前提的PR后面由于需求的变便去忙别的事情了,等到要做这个需求的我时候,发现已经 落后版本了,并且有很多文件的冲突,然后就用rebase ...

  5. Github上面拉取别人提交的PR

    在github上面协同开发,避免不了拉取别的同学的PR,那么如何拉取呢? 1.首先我们看下upstream liz@liz-PC:~/jimeng/handle-api$ git remote -v ...

  6. 计算机网络-CSMA/CD

    假定1km长的CSMA/CD网络的传输速率为1Gbit/s.设信号在网络上的传播速率为200000km/s,则能够使用此协议的最短帧长是? 答案:2×104bit/s 解析:C=2×105km/s,即 ...

  7. 数据结构和算法(Golang实现)(11)常见数据结构-前言

    常见数据结构及算法 数据结构主要用来组织数据,也作为数据的容器,载体. 各种各样的算法,都需要使用一定的数据结构来组织数据. 常见的典型数据结构有: 链表 栈和队列 树 图 上述可以延伸出各种各样的术 ...

  8. Cilium架构 (Cilium 2)

    Cilium架构 译自:http://docs.cilium.io/en/stable/architecture/ 本文档描述了Cilium的架构.它通过记录BPF数据路径(datapath)的钩子来 ...

  9. asp.net core webapi Session 跨域

    在ajax 请求是也要加相应的东西 $.ajax({ url:url, //加上这句话 xhrFields: { withCredentials: true } success:function(re ...

  10. SpringCloud-Gateway 网关路由、断言、过滤

    Gateway 简介 是什么? Spring Cloud 全家桶中有个很重要的组件:网关.在 1.x 版本中使用的是 Zuul 网关,但是到了 2.x,由于Zuul的升级不断跳票,Spring Clo ...