A8769 | Magical Boxes
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
The first line of input contains an integer $n$ ( $1<=n<=10^{5}$ ), 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}<=10^{9}$ , $1<=a_{i}<=10^{9}$ ), which means that Emuskald has $a_{i}$ boxes with side length $2^{k_{i}}$ . It is guaranteed that all of $k_{i}$ are distinct.
输出格式
Output a single integer $p$ , such that the smallest magical box that can contain all of Emuskald’s boxes has side length $2^{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.
In the second test case, we can put all four small boxes into a box with side length 2.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted