#abc323d. D - Merge Slimes

D - Merge Slimes

Score : 425425 points

问题描述

最初有 NN 种不同大小的史莱姆。
具体来说,对于每个 1iN1\leq i\leq N,存在大小为 SiS_i 的史莱姆共 CiC_i 只。

高桥可以任意次数(包括零次)以任意顺序进行史莱姆合成操作。
史莱姆合成的操作方式如下:

  • 选择两只 相同大小 的史莱姆。设它们的大小为 XX,则会出现一只大小为 2X2X 的新史莱姆。随后,两只原始史莱姆消失。

高桥想要尽量减少史莱姆的数量。通过最优的合成序列,他最终能得到的史莱姆最少是多少只呢?

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Initially, there are NN sizes of slimes.
Specifically, for each 1iN1\leq i\leq N, there are CiC_i slimes of size SiS_i.

Takahashi can repeat slime synthesis any number of times (possibly zero) in any order.
Slime synthesis is performed as follows.

  • Choose two slimes of the same size. Let this size be XX, and a new slime of size 2X2X appears. Then, the two original slimes disappear.

Takahashi wants to minimize the number of slimes. What is the minimum number of slimes he can end up with by an optimal sequence of syntheses?

Constraints

  • 1N1051\leq N\leq 10^5
  • 1Si1091\leq S_i\leq 10^9
  • 1Ci1091\leq C_i\leq 10^9
  • S1,S2,,SNS_1,S_2,\ldots,S_N are all different.
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN

S1S_1 C1C_1

S2S_2 C2C_2

\vdots

SNS_N CNC_N

Output

Print the minimum possible number of slimes after Takahashi has repeated the synthesis.

Sample Input 1

3
3 3
5 1
6 1

Sample Output 1

3

Initially, there are three slimes of size 33, one of size 55, and one of size 66.
Takahashi can perform the synthesis twice as follows:

  • First, perform the synthesis by choosing two slimes of size 33. There will be one slime of size 33, one of size 55, and two of size 66.
  • Next, perform the synthesis by choosing two slimes of size 66. There will be one slime of size 33, one of size 55, and one of size 1212.

No matter how he repeats the synthesis from the initial state, he cannot reduce the number of slimes to 22 or less, so you should print 33.

Sample Input 2

3
1 1
2 1
3 1

Sample Output 2

3

He cannot perform the synthesis.

Sample Input 3

1
1000000000 1000000000

Sample Output 3

13

update @ 2024/3/10 01:44:37

}