题目链接

https://vjudge.net/problem/CodeForces-455A

题面

Description

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.

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 a1, a2, ..., a**n (1 ≤ a**i ≤ 105).

Output

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

Examples

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.

题解

简单DP题,记录一下每个数有多少个,\(dp[i]\)表示消除值为i的数字或者不消除值为i的数字的最大分数,直接从最小的数字的值开始dp是否消除即可

AC代码

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 100050
using namespace std;
long long f[N];
long long cnt[N];
bool vis[N];
long long a[N];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
}
sort (a + 1, a + n + 1);
for (int i = 1; i <= n; i++) {
cnt[a[i]]++;
}
long long ans = 0;
for (int i = a[1]; i <= a[n]; i++) {
f[i] = max(f[i - 1], f[i - 2] + cnt[i] * i);
ans = max(ans, f[i]);
}
printf("%lld\n", ans);
return 0;
}

CodeForces-455A Boredom的更多相关文章

  1. CodeForces 455A Boredom (DP)

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

  2. Codeforces 455A - Boredom - [DP]

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

  3. Codeforces 455A Boredom (线性DP)

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

  4. Codeforces 455A Boredom 取数字的dp

    题目链接:点击打开链接 给定一个n长的序列 删除x这个数就能获得x * x的个数 的分数,然后x+1和x-1这2个数会消失.即无法获得这2个数的分数 问最高得分. 先统计每一个数出现的次数.然后dp一 ...

  5. CodeForces 456-C Boredom

    题目链接:CodeForces -456C Description Alex doesn't like boredom. That's why whenever he gets bored, he c ...

  6. CF 455A Boredom

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

  7. Codeforces 445A Boredom(DP+单调队列优化)

    题目链接:http://codeforces.com/problemset/problem/455/A 题目大意:有n个数,每次可以选择删除一个值为x的数,然后值为x-1,x+1的数也都会被删除,你可 ...

  8. Codeforces 853C - Boredom

    853C - Boredom 题意 给出一个矩阵,每行每列有且仅有一个点.每次询问一个子矩形,问这些点构成的矩形有多少个与给定的矩形相交(两个处于对角线上的点可以组成矩形). 分析 考虑矩形周围 8 ...

  9. codeforces每日一题1-10

    目录: 1.1093D. Beautiful Graph(DFS染色) 2.514C - Watto and Mechanism(Tire) 3.69E.Subsegments(STL) 4.25C. ...

  10. dp学习笔记(各种dp,比较杂)

    HDU1176 中文题意不多解释了. 建一个二维dp数组,dp[ i ][ j ]表示第 i 秒落在 j 处一个馅饼.我们需要倒着DP,为什么呢,从 0秒,x=5处出发,假如沿数组正着往下走,终点到哪 ...

随机推荐

  1. HDU1215 七夕节(模拟 数学)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1215 七夕节 Time Limit: 2000/1000 MS (Java/Others)    Me ...

  2. lucene&solr学习——分词器

    下图是语汇单元的生成过程: 从一个Reader字符流开始,创建基于Reader的Tokenizer分词器,经过三个TokenFilter生成语汇单元Tokens. 要看分词器的分析效果,只需要看Tok ...

  3. 手把手教你玩转 CSS3 3D 技术

    css3的3d起步 要玩转css3的3d,就必须了解几个词汇,便是透视(perspective).旋转(rotate)和移动(translate).透视即是以现实的视角来看屏幕上的2D事物,从而展现3 ...

  4. datagrid中设置编辑,删除列是否可以访问

    foreach (RepeaterItem Item in rpt_Result.Items) { LinkButton edit = (LinkButton)Item.FindControl(&qu ...

  5. 转载:/etc/security/limits.conf 控制文件描述符,进程数,栈大小

    原文地址:http://ilikedo.iteye.com/blog/1554822 linux下安装Oracle 一般都会修改/etc/security/limits.conf这个文件,但是这里面的 ...

  6. D - 湫湫系列故事——减肥记II

    虽然制定了减肥食谱,但是湫湫显然克制不住吃货的本能,根本没有按照食谱行动! 于是,结果显而易见… 但是没有什么能难倒高智商美女湫湫的,她决定另寻对策——吃没关系,咱吃进去再运动运动消耗掉不就好了? 湫 ...

  7. 使用nginx对spring boot项目进行代理

    摘要:使用nginx对spring boot项目进行反向代理,并且使用轮询均衡负载策略 均衡负载与集群 集群和均衡都涉及到多个机器提供的服务的问题 不同点是,集群是互相通信.协同的的多个服务,服务之前 ...

  8. kali下添加用户和权限分配

    1.添加用户 useradd -m test #-m的意思是创建用户的主目录 2.为用户test设置密码. passwd test 3.为添加的用户赋予权限(-a 添加 :-G 群组) 如果没有这一步 ...

  9. CentOS下删除MySql

    1.查找以前是否装有mysql rpm -qa | grep -i mysql 显示之前安装了: MySQL-client-5.5.49-1.linux2.6.i386 MySQL-server-5. ...

  10. Java OOP——第三章 多态

    1.多态:(polymorphism): 是具有表现多种形态能力的特征: (专业化的说法:)同一个实现接口(引用类型),使用不同的实例而执行不同的操作 指一个引用(类型)在不同情况下的多种状态.也可以 ...