CF455A.Boredom

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.

Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it a__k) and delete it, at that all elements equal to a__k + 1 and a__k - 1 also must be deleted from the sequence. That step brings a__k points to the player.

Alex is a perfectionist, so he decided to get as many points as possible. Help him.

亚历克斯不喜欢无聊。因此,每当他感到无聊时,就会想出一些游戏来玩。在一个漫长的冬夜,他想出了一个游戏,并决定开始玩。

给定一个由 nn 个整数组成的序列 aa。玩家可以进行若干步操作。在单步操作中,他可以选择序列中的一个元素(记为 aka_k)并将其删除;此时,序列中所有等于 ak+1a_k + 1 和 ak−1a_k - 1 的元素也必须一并删除。该步操作为玩家赢得 aka_k 分。

亚历克斯是个完美主义者,因此他希望获得尽可能多的分数。请帮助他。

输入格式

The first line contains integer n (1 ≤ n ≤ 105) that shows how many numbers are in Alex's sequence.

The second line contains n integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 105).

第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5),表示 Alex 序列中数字的个数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1051 \leq a_i \leq 10^5)。

输出格式

Print a single integer — the maximum number of points that Alex can earn.

输出一个整数——Alex 能获得的最高分数。

输入输出样例

  • 输入#1

    2
    1 2

    输出#1

    2
  • 输入#2

    3
    1 2 3

    输出#2

    4
  • 输入#3

    9
    1 2 1 3 2 2 2 2 3

    输出#3

    10

说明/提示

Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.

考虑第三个测试样例。第一步,我们需要选择任意一个等于 2 的元素。完成该步后,序列变为

2, 2, 2, 22,\,2,\,2,\,2

接着我们进行 4 步操作,每步均选择任意一个等于 2 的元素。总共获得 10 分。

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

首页