CF269A.Magical Boxes

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 2_k_ (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 2_k_ - 1 into one box of side length 2_k_, 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.

埃穆斯卡尔德是一位著名的魔术师。他的一项标志性戏法涉及一套魔法盒子。该戏法的核心在于将盒子嵌套装入其他盒子中。

从俯视图看,每个魔法盒子都是一个正方形,其边长为 2k2^k(其中 kk 为整数,且 k≥0k \geq 0)个单位。若盒子 vv 的边长严格小于盒子 uu 的边长,则盒子 vv 可以放入盒子 uu 中。特别地,埃穆斯卡尔德可将 4 个边长为 2k−12^{k-1} 的盒子放入一个边长为 2k2^k 的盒子中,如下图所示:

埃穆斯卡尔德即将开启全球巡演之旅,需要为他的魔法盒子打包。他决定将所有盒子全部装入另一个魔法盒子中,但魔法盒子的制作成本相当高昂。请帮助他找出能容纳所有盒子的最小魔法盒子。

输入格式

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 k__i and a__i (0 ≤ k__i ≤ 109, 1 ≤ a__i ≤ 109), which means that Emuskald has a__i boxes with side length 2_k__i_. It is guaranteed that all of k__i are distinct.

输入的第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5),表示 Emuskald 拥有的不同尺寸的盒子数量。接下来的 nn 行中,每行包含两个整数 kik_i 和 aia_i(0≤ki≤1090 \leq k_i \leq 10^9,1≤ai≤1091 \leq a_i \leq 10^9),表示 Emuskald 拥有 aia_i 个边长为 2ki2^{k_i} 的盒子。保证所有的 kik_i 互不相同。

输出格式

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

输出一个整数 pp,使得能够容纳所有 Emuskald 的盒子的最小魔法盒子的边长为 2p2^p。

输入输出样例

  • 输入#1

    2
    0 3
    1 5

    输出#1

    3
  • 输入#2

    1
    0 4

    输出#2

    1
  • 输入#3

    2
    1 10
    2 2

    输出#3

    3

说明/提示

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.

图片说明:如果我们有 3 个边长为 2 的盒子和 5 个边长为 1 的盒子,那么我们可以将所有这些盒子放入一个边长为 4 的盒子中,例如如图所示。

在第二个测试用例中,我们可以将全部 4 个小盒子放入一个边长为 2 的盒子中。

输入解题思路,AI测评打分。不知道怎么写?

首页