Type: Default 2000ms 1024MiB

[ABC315C] Flavors

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

[ABC315C] Flavors

题面翻译

给定 nn 个二元组,每个二元组形如 (F,S)(F,S),要求选定 22 个二元组,若 FF 相等,则贡献为 S1+S22(S1S2)S_{1}+\frac{S_{2}}{2}(S_{1} \ge S_{2});反之,贡献为 S1+S2S_{1}+S_{2},最大化贡献。1n3×1051 \le n \le 3 \times 10^5

题目描述

We have N cups of ice cream. The flavor and deliciousness of the i-th cup are Fi and Si, respectively (Si is an even number).

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

  • Let s and t (st) be the deliciousness of the eaten cups.
    • If the two cups have different flavors, your satisfaction is s+t.
    • Otherwise, your satisfaction is s+t/2.

Find the maximum achievable satisfaction.

输入格式

输入格式如下:

N N F1 F_1 S1 S_1 F2 F_2 S2 S_2 \vdots FN F_N SN S_N

输出格式

输出一个正整数表示答案。

样例 #1

样例输入 #1

4
1 4
2 10
2 8
3 6

样例输出 #1

16

样例 #2

样例输入 #2

4
4 10
3 2
2 4
4 12

样例输出 #2

17

提示

数据范围

  • 输入都是正整数
  • 2  N  3 × 105 2\ \le\ N\ \le\ 3\ \times\ 10^5
  • 1  Fi  N 1\ \le\ F_i\ \le\ N
  • 2  Si  109 2\ \le\ S_i\ \le\ 10^9
  • Si S_i 是偶数

CSP-J训练赛(三)

Not Attended
Status
Done
Rule
IOI
Problem
14
Start at
2024-8-10 7:30
End at
2024-8-10 12:00
Duration
4.5 hour(s)
Host
Partic.
11