#abc315c. C - Flavors

C - Flavors

Score : 300300 points

问题描述

我们有 NN 个冰淇淋杯。
ii 个冰淇淋杯的口味和美味程度分别为 FiF_iSiS_i(其中 SiS_i 是偶数)。

你需要从这 NN 个冰淇淋杯中选择并吃掉两个。
你的满意度定义如下:

  • sstt(满足 sts \ge t)为所吃掉的两个冰淇淋杯的美味程度。
    • 如果两个冰淇淋杯口味不同,你的满意度为 s+t\displaystyle s+t
    • 否则,你的满意度为 s+t2\displaystyle s + \frac{t}{2}

求最大可获得的满意度。

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

Problem Statement

We have NN cups of ice cream.
The flavor and deliciousness of the ii-th cup are FiF_i and SiS_i, respectively (SiS_i is an even number).

You will choose and eat two of the NN cups.
Your satisfaction here is defined as follows.

  • Let ss and tt (sts \ge t) be the deliciousness of the eaten cups.
    • If the two cups have different flavors, your satisfaction is s+t\displaystyle s+t.
    • Otherwise, your satisfaction is s+t2\displaystyle s + \frac{t}{2}.

Find the maximum achievable satisfaction.

Constraints

  • All input values are integers.
  • 2N3×1052 \le N \le 3 \times 10^5
  • 1FiN1 \le F_i \le N
  • 2Si1092 \le S_i \le 10^9
  • SiS_i is even.

Input

Input is given from Standard Input in the following format:

NN

F1F_1 S1S_1

F2F_2 S2S_2

\vdots

FNF_N SNS_N

Output

Print the answer as an integer.

Sample Input 1

4
1 4
2 10
2 8
3 6

Sample Output 1

16

Consider eating the second and fourth cups.

  • The second cup has a flavor of 22 and deliciousness of 1010.
  • The fourth cup has a flavor of 33 and deliciousness of 66.
  • Since they have different flavors, your satisfaction is 10+6=1610+6=16.

Thus, you can achieve the satisfaction of 1616.
You cannot achieve a satisfaction greater than 1616.

Sample Input 2

4
4 10
3 2
2 4
4 12

Sample Output 2

17

Consider eating the first and fourth cups.

  • The first cup has a flavor of 44 and deliciousness of 1010.
  • The fourth cup has a flavor of 44 and deliciousness of 1212.
  • Since they have the same flavor, your satisfaction is 12+102=1712+\frac{10}{2}=17.

Thus, you can achieve the satisfaction of 1717.
You cannot achieve a satisfaction greater than 1717.

update @ 2024/3/10 09:00:33