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 ak)
and delete it, at that all elements equal to ak + 1 and ak - 1 also must be deleted from the sequence.
That step brings ak points to the player.

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

Input

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 a1a2, ..., an (1 ≤ ai ≤ 105).

Output

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

Example

Input
2
1 2
Output
2
Input
3
1 2 3
Output
4
Input
9
1 2 1 3 2 2 2 2 3
Output
10

Note

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.

题意:就是给你N个数。你可选择大小的为A的数,但是A-1和A+1必须从数队移走。

题解:本题与数的顺序无关(这时候想到了DP),我们先对其排序。然后找其状态转移方程。假设dp[j]表示从1加到j 时最大值。则dp[j]=max(dp[j-1],dp[j-2]+i*cnt[i]).【ps:cnt[i]表示数值为】

AC代码为:

#include<iostream>

#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

using namespace std;

long long  n, a[100002], cot[100002], d[100002];

int main()

{
cin >> n;

long long Max = 0;

for (int i = 1; i <= n; i++)
{
cin >> a[i];
if (a[i] > Max)
Max = a[i];
cot[a[i]]++;
}

d[1] = cot[1];  d[0] = 0;

for (int i = 2; i <= Max; i++)
d[i] = max(d[i - 1], d[i - 2] + cot[i] * i);

cout << d[Max] << endl;

return 0;

}

Coderforces-455A的更多相关文章

  1. coderforces #387 Servers(模拟)

    Servers time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...

  2. coderforces #384 D Chloe and pleasant prizes(DP)

    Chloe and pleasant prizes time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  3. coderforces 731c

    题目大意:给出m组数据,每组数据包括两个数Li与Ri,分别表示左右袜子的索引(下标),表示这一天要穿的袜子:而我们要使得每天穿的这两只袜子的颜色相同,所以可以改变袜子的颜色,每次只能改变一只袜子的颜色 ...

  4. coderforces 721b

    题目描述: B. Passwords time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. CoderForces 280B(记忆化搜索)

    题目大意:一个纸牌游戏,52张纸牌排成一列,每张纸牌有面值和花色两种属性.每次操作可以用最后一张纸牌将倒数第二张或者倒数第四张替换,但前提是两张牌的花色或者面值相同.问最终能否只剩一张牌. 题目分析: ...

  6. CodeForces 455A Boredom (DP)

    Boredom 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/G Description Alex doesn't like b ...

  7. Codeforces 455A Boredom (线性DP)

    <题目链接> 题目大意:给定一个序列,让你在其中挑选一些数,如果你选了x,那么你能够得到x分,但是该序列中所有等于x-1和x+1的元素将全部消失,问你最多能够得多少分. 解题分析:从小到大 ...

  8. Codeforces 455A - Boredom - [DP]

    题目链接:https://codeforces.com/problemset/problem/455/A 题意: 给出一个 $n$ 个数字的整数序列 $a[1 \sim n]$,每次你可以选择一个 $ ...

  9. CF 455A Boredom

    A. Boredom time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  10. CoderForces 689A Mike and Cellphone (水题)

    题意:给定一个手机键盘数字九宫格,然后让你判断某种操作是不是唯一的,也就是说是不是可以通过平移也能实现. 析:我的想法是那就平移一下,看看能实现,就四种平移,上,下,左,右,上是-3,要注意0变成8, ...

随机推荐

  1. ZeroC ICE的远程调用框架 ASM与defaultServant,ServantLocator

    ASM与defaultServant,ServantLocator都是与调用调度(Dispatch)相关的. ASM是ServantManager中的一张二维表_servantMapMap,默认Ser ...

  2. Microsoft Dynamics CRM 批量上传web资源(非官方WebResourceUtility)并替换实体图标

    背景: 去年以前可以按照目录WebResourceUtility批量上传web资源,昨天发现用不了了,拿到WebResourceUtility源码改了一下都不是很方便,感觉官方写的太冗余,太长了,跟我 ...

  3. vim用户手册笔记常用操作整理

    "x"命令可以删除一个字符 "d"命令可以后跟任何一个位移命令,它将删除从当前光标起到位移的终点处的文本内容dw "c",改变命令例如cw ...

  4. GeoServer CQL查询时中文问题

    1.GeoServer可以进行CQL与ECQL过滤,wms和wfs都可以 2.CQL与ECQL查询时,当传中文时会报错.将中文转为Unicode编码后就可以 /* *js Unicode编码转换 */ ...

  5. 用图解&&实例讲解php是如何实现websocket实时消息推送的

    WebSocket是 HTML5 开始提供的一种在单个 TCP 连接上进行全双工通讯的协议. 以前的推送技术使用 Ajax 轮询,浏览器需要不断地向服务器发送http请求来获取最新的数据,浪费很多的带 ...

  6. [FPGA]Verilog利用PWM调制巧妙完成RGB三色彩虹呼吸灯(给简约的题目以美妙的解答)

    概述 实现彩虹呼吸灯 题目就是这么简短,但这是目前我碰到的最有意思的一道题目,因为他有无数种解决方法,并且每一种都是那么高级或者巧妙,比如 可以利用3路不同初相的PWM调制信号驱动三颗RGB灯重叠呼吸 ...

  7. 2019-9-29,php基础学习,笔记

    cobalt strike简单使用cobalt是一个后渗透测试工具,基于java开发,适用于团队间协同作战,简称"cs"cs分为客户端和服务端,一般情况下我们称服务端为团队服务器, ...

  8. JSON的使用场景及注意事项介绍

    上篇我们讲解了JSON的诞生原因是因为XML整合到HTML中各个浏览器实现的细节不尽相同,所以道格拉斯·克罗克福特(Douglas Crockford) 和 奇普·莫宁斯达(Chip Mornings ...

  9. 【Luogu P1265】公路修建

    Luogu P1265 本来一开始我用的Kruskal--但是由于double类型8字节,所以MLE了. 很容易发现这是一道最小生成树的题目. 值得注意的是题目中给的第二个限制,只存在唯一情况即这个环 ...

  10. Spring项目中优雅的异常处理

    前言 如今的Java Web项目多是以 MVC 模式构建的,通常我们都是将 Service 层的异常统一的抛出,包括自定义异常和一些意外出现的异常,以便进行事务回滚,而 Service 的调用者 Co ...