【Magical Boxes】【CodeForces - 270C】(思维+贪心)

版权声明:本人原创,未经许可,不得转载 https://blog.csdn.net/qq_42505741/article/details/84171878

题目:

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.

解题报告:一上眼这个题目就想到后边的大格子是不是能够将前边的小格子装进去,所以就会涉及到怎么装的问题,前边的小格子最小能够被多大的格子装下去,之后新进来的格子是不是能够在这个的前提下继续存放,如果不能的话,咱们就更新一下最大的格子的尺寸。

ac代码:

#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;


int main()
{
	int s,n,k,t;
	scanf("%d",&n);
	s=0;
	while(n--)
	{
		scanf("%d%d",&k,&t);
		if(s<k+1)
			s=k+1;
		t--;
		while(t)
		{
			k++;
			t/=4;
		}
		if(k>s)
			s=k;
	}
	printf("%d\n",s);
}

猜你喜欢

转载自blog.csdn.net/qq_42505741/article/details/84171878