#abc228h. H - Histogram
H - Histogram
Score : points
问题描述
给定两个长度为 的整数序列: 和 。
你可以执行以下操作任意次数,包括零次。
- 选择一个整数 ,满足 ,并以 日元(日本货币单位)的成本将 的值加 。
完成所有操作后,你需要支付 日元,其中 是 中元素的不同取值个数。
请问你至少需要支付多少总金额?
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Given are integer sequences of length each: and .
You can do the following operation any number of times, possibly zero.
- Choose an integer such that and add to the value of , for a cost of yen (Japanese currency).
After you are done with the operation, you have to pay yen, where is the number of different values among the elements of .
What is the minimum total amount of money you have to pay?
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print a number representing the answer.
Sample Input 1
3 5
3 2
2 4
4 3
Sample Output 1
12
After adding to , there will be two different values among the elements of , for a total cost of yen. It is impossible to make the total cost less than this.
Sample Input 2
1 1
1 1
Sample Output 2
1
Sample Input 3
7 7
3 2
1 7
4 1
1 8
5 2
9 8
2 1
Sample Output 3
29
update @ 2024/3/10 10:00:31