#4878. Merge Slimes

0

Merge Slimes

Merge Slimes

题目描述

Initially, there are NN sizes of slimes.
Specifically, for each 1≤i≤N1\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?

输入格式

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

输出格式

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

3
3 3
5 1
6 1
3
3
1 1
2 1
3 1
3
1
1000000000 1000000000
13

提示

1≤N≤1051\leq N\leq 10^5 1≤Si≤1091\leq S_i\leq 10^9 1≤Ci≤1091\leq C_i\leq 10^9 S1,S2,…,SNS_1,S_2,\ldots,S_N are all different. All input values are integers.最初,有三个大小为 33 的史莱姆,一个大小为 55 的史莱姆,和一个大小为 66 的史莱姆。
Takahashi 可以按如下方式进行两次合成:

首先,选择两个大小为 33 的史莱姆进行合成。此时会剩下一个大小为 33 的史莱姆,一个大小为 55 的史莱姆,和两个大小为 66 的史莱姆。 接着,选择两个大小为 66 的史莱姆进行合成。此时会剩下一个大小为 33 的史莱姆,一个大小为 55 的史莱姆,和一个大小为 1212 的史莱姆。

无论他如何从初始状态重复合成,都无法将史莱姆的数量减少到 22 或更少,所以应当输出 33。
他不能进行合成。

标签: AtCoder|abc323D

来源

AtCoder|abc323D