#abc323d. D - Merge Slimes
D - Merge Slimes
Score : points
问题描述
最初有 种不同大小的史莱姆。
具体来说,对于每个 ,存在大小为 的史莱姆共 只。
高桥可以任意次数(包括零次)以任意顺序进行史莱姆合成操作。
史莱姆合成的操作方式如下:
- 选择两只 相同大小 的史莱姆。设它们的大小为 ,则会出现一只大小为 的新史莱姆。随后,两只原始史莱姆消失。
高桥想要尽量减少史莱姆的数量。通过最优的合成序列,他最终能得到的史莱姆最少是多少只呢?
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Initially, there are sizes of slimes.
Specifically, for each , there are slimes of size .
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 , and a new slime of size 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
- are all different.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
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 , one of size , and one of size .
Takahashi can perform the synthesis twice as follows:
- First, perform the synthesis by choosing two slimes of size . There will be one slime of size , one of size , and two of size .
- Next, perform the synthesis by choosing two slimes of size . There will be one slime of size , one of size , and one of size .
No matter how he repeats the synthesis from the initial state, he cannot reduce the number of slimes to or less, so you should print .
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