AT_abc461_c.Variety

普及-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are NN gems. The color (represented as an integer) of the ii-th gem is CiC_i and its value is ViV_i.

Choose KK gems from these NN gems. Here, the chosen gems must have at least MM distinct colors.

Find the maximum possible total value of the chosen gems. (Such a choice is always possible in the given input.)

有 NN 颗宝石。第 ii 颗宝石的颜色(用一个整数表示)为 CiC_i,其价值为 ViV_i。

从这 NN 颗宝石中选出 KK 颗宝石,要求所选宝石中至少包含 MM 种不同的颜色。

求所选宝石的总价值的最大可能值。(题目保证输入数据下总存在满足条件的选择。)

输入格式

The input is given from Standard Input in the following format:

NN KK MM
C1C_1 V1V_1
C2C_2 V2V_2
⋮\vdots
CNC_N VNV_N

输入从标准输入中按以下格式给出:

NN KK MM
C1C_1 V1V_1
C2C_2 V2V_2
⋮\vdots
CNC_N VNV_N

输出格式

Output the maximum possible total value of the chosen gems as an integer.

输出所选宝石的最大可能总价值(整数)。

输入输出样例

  • 输入#1

    5 3 2
    1 30
    1 40
    1 50
    2 10
    3 20

    输出#1

    110
  • 输入#2

    5 3 3
    1 30
    1 40
    1 50
    2 10
    3 20

    输出#2

    80
  • 输入#3

    5 5 1
    4 1000000000
    5 1000000000
    4 1000000000
    5 1000000000
    4 1000000000

    输出#3

    5000000000

说明/提示

Sample 1 Explanation:
In this sample, choose three gems from five gems. The chosen gems must have at least two distinct colors.

Choosing gems 2,3,52, 3, 5 gives colors 1,1,31, 1, 3, which are two distinct colors. Their total value is 40+50+20=11040 + 50 + 20 = 110, and this is the maximum possible value.

Sample 2 Explanation:
The gems and the number to choose are the same as in Sample Input 1, but the chosen gems must have at least three distinct colors.

Choosing gems 3,4,53, 4, 5 gives colors 1,2,31, 2, 3, which are three distinct colors. Their total value is 50+10+20=8050 + 10 + 20 = 80, and this is the maximum possible value.

Sample 3 Explanation:
Beware of overflow.

Constraints

  • 1≤M≤K≤N≤2×1051 \leq M \leq K \leq N \leq 2 \times 10^5
  • 1≤Ci≤N1 \leq C_i \leq N
  • 1≤Vi≤1091 \leq V_i \leq 10^9
  • There exist gems of at least MM distinct colors.
  • All input values are integers.

样例 1 解释:
本样例中,需从五颗宝石中选出三颗,且所选宝石的颜色种类数至少为两种。

选择宝石 2,3,52, 3, 5,对应颜色为 1,1,31, 1, 3,共两种不同颜色。其总价值为 40+50+20=11040 + 50 + 20 = 110,这是可能的最大值。

样例 2 解释:
宝石集合及需选择的宝石数量与样例输入 1 相同,但所选宝石的颜色种类数至少为三种。

选择宝石 3,4,53, 4, 5,对应颜色为 1,2,31, 2, 3,共三种不同颜色。其总价值为 50+10+20=8050 + 10 + 20 = 80,这是可能的最大值。

样例 3 解释:
注意整数溢出问题。

约束条件

  • 1≤M≤K≤N≤2×1051 \leq M \leq K \leq N \leq 2 \times 10^5
  • 1≤Ci≤N1 \leq C_i \leq N
  • 1≤Vi≤1091 \leq V_i \leq 10^9
  • 至少存在 MM 种不同颜色的宝石。
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页