题目链接

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

  1. 2
  2. 1 2

Output

  1. 2

Input

  1. 3
  2. 1 2 3

Output

  1. 4

Input

  1. 9
  2. 1 2 1 3 2 2 2 2 3

Output

  1. 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代码

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. #define N 100050
  6. using namespace std;
  7. long long f[N];
  8. long long cnt[N];
  9. bool vis[N];
  10. long long a[N];
  11. int main() {
  12. int n;
  13. scanf("%d", &n);
  14. for (int i = 1; i <= n; i++) {
  15. scanf("%lld", &a[i]);
  16. }
  17. sort (a + 1, a + n + 1);
  18. for (int i = 1; i <= n; i++) {
  19. cnt[a[i]]++;
  20. }
  21. long long ans = 0;
  22. for (int i = a[1]; i <= a[n]; i++) {
  23. f[i] = max(f[i - 1], f[i - 2] + cnt[i] * i);
  24. ans = max(ans, f[i]);
  25. }
  26. printf("%lld\n", ans);
  27. return 0;
  28. }

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. 【luogu P3178 [HAOI2015]树上操作】 题解

    题目链接:https://www.luogu.org/problemnew/show/P3178 模板题 菜 #include <cstdio> #include <cstring& ...

  2. 【luogu P1801 黑匣子_NOI导刊2010提高(06)】 题解

    题目链接:https://www.luogu.org/problemnew/show/P1801 替罪羊树吼啊! #include <cstdio> #include <cstrin ...

  3. Rest API 开发 学习笔记

    概述 REST 从资源的角度来观察整个网络,分布在各处的资源由URI确定,而客户端的应用通过URI来获取资源的表示方式.获得这些表徵致使这些应用程序转变了其状态.随着不断获取资源的表示方式,客户端应用 ...

  4. mysql复制表数据,多表数据复制到一张表

    对于mysql 复制表数据可以使用 insert into select 方式 示例: $sql="insert into icarzoo.provider(providerId,provi ...

  5. Xshell中使用FTP/SFTP工具下载文件

    (1)sftp host_ip,输入用户名/密码 (2)通过cd命令找到远程服务器要拷贝的文件: 通过lcd命令指定本地保存地址. (3)通过get filename拷贝文件 (4)在本地查看,已经可 ...

  6. 使用actionerror做失败登录验证

    一. 登录页面中放置如下代码: <h4>员工登录</h4> <div style="color:red"> <s:actionerror/ ...

  7. xcode 快捷键大全、XCode常用快捷键图文介绍

    其实就是设置里面的快捷键变成了文字版,刚开始用Xcode是不是发现以前熟悉的开发环境的快捷键都不能用了?怎么快捷运行,停止,编辑等等.都不一样了.快速的掌握这些快捷键,能提供开发的效率. 其实快捷键在 ...

  8. Ajax提交乱码

    1. 页面码 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&g ...

  9. Mac上从gitlab上拉项目实战总结

    建立公钥,私钥 https://blog.csdn.net/jigongdajiang/article/details/65441923 2019-01-03 比较喜欢使用图形化界面

  10. mysql 使用 FIND_IN_SET 来查询数据

    mysql中find_in_set函数很有意思,它的功能是查找以英文逗号隔开的值,我们可以将数据存储类似为1,2,3,4格式.今天我们就来看看在thinkphp中怎样正确地使用find_in_set函 ...