#abc228h. H - Histogram

H - Histogram

Score : 600600 points

问题描述

给定两个长度为 NN 的整数序列:A=(A1,,AN)A = (A_1, \dots, A_N)C=(C1,,CN)C = (C_1, \dots, C_N)

你可以执行以下操作任意次数,包括零次。

  • 选择一个整数 ii,满足 1iN1 \leq i \leq N,并以 CiC_i 日元(日本货币单位)的成本将 AiA_i 的值加 11

完成所有操作后,你需要支付 K×XK \times X 日元,其中 KKAA 中元素的不同取值个数。

请问你至少需要支付多少总金额?

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

Problem Statement

Given are integer sequences of length NN each: A=(A1,,AN)A = (A_1, \dots, A_N) and C=(C1,,CN)C = (C_1, \dots, C_N).

You can do the following operation any number of times, possibly zero.

  • Choose an integer ii such that 1iN1 \leq i \leq N and add 11 to the value of AiA_i, for a cost of CiC_i yen (Japanese currency).

After you are done with the operation, you have to pay K×XK \times X yen, where KK is the number of different values among the elements of AA.

What is the minimum total amount of money you have to pay?

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 1X1061 \leq X \leq 10^6
  • 1Ai,Ci106(1iN)1 \leq A_i, C_i \leq 10^6 \, (1 \leq i \leq N)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN XX

A1A_1 C1C_1

\vdots

ANA_N CNC_N

Output

Print a number representing the answer.

Sample Input 1

3 5
3 2
2 4
4 3

Sample Output 1

12

After adding 11 to A1A_1, there will be two different values among the elements of AA, for a total cost of C1+2×X=12C_1 + 2 \times X = 12 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