CF#260 div2 C. Boredom

Codeforces Round #260

C. Boredom
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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

Output

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

Sample test(s)
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.

题意:给出一堆数,一次操作是取某个数,然后等于(它+1)或(它-1)的数全删掉,得到(它)分,求最高得分。

有两种dp方法,一种排序后dp[i][j]表示取到第i个得到的最大分,j表示取或不取;

另一种是我用的,dp[i]表示在1~i的数中取,必取i,得到的最高分,从2扫到100000。

            dp[i]=dp[i-];
if(a[i]>)dp[i]=max(dp[i],dp[i-]+1LL*i*a[i]);

注意10^5 * 10^5= 10^10会爆long long,我就是这样掉分飞起的。

 //#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
#define ll long long
#define usint unsigned int
#define mz(array) memset(array, 0, sizeof(array))
#define minf(array) memset(array, 0x3f, sizeof(array))
#define REP(i,n) for(i=0;i<(n);i++)
#define FOR(i,x,n) for(i=(x);i<=(n);i++)
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define WN(x) printf("%d\n",x);
#define RE freopen("D.in","r",stdin)
#define WE freopen("1biao.out","w",stdout) const int maxn=;
int a[maxn];
ll dp[maxn]; int main(){
ll ma;
int n,i,x;
while(scanf("%d",&n)!=EOF){
mz(a);
for(i=;i<n;i++){
scanf("%d",&x);
a[x]++;
}
dp[]=;
dp[]=a[];
ma=dp[];
for(i=;i<=;i++)
{
dp[i]=dp[i-];
if(a[i]>)dp[i]=max(dp[i],dp[i-]+1LL*i*a[i]);
if(dp[i]>ma)ma=dp[i];
}
printf("%I64d\n",ma);
}
return ;
}

CF456C Boredom (DP)的更多相关文章

  1. Codeforces Round #260 (Div. 2)C. Boredom(dp)

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

  2. Codeforces Round #260 (Div. 1) 455 A. Boredom (DP)

    题目链接:http://codeforces.com/problemset/problem/455/A A. Boredom time limit per test 1 second memory l ...

  3. CodeForces 455A Boredom (DP)

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

  4. Codeforces Round #260 (Div. 1) Boredom(DP)

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

  5. codeforces #260 DIV 2 C题Boredom(DP)

    题目地址:http://codeforces.com/contest/456/problem/C 脑残了. .DP仅仅DP到了n. . 应该DP到10w+的. . 代码例如以下: #include & ...

  6. LightOJ 1033 Generating Palindromes(dp)

    LightOJ 1033  Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  7. lightOJ 1047 Neighbor House (DP)

    lightOJ 1047   Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...

  8. UVA11125 - Arrange Some Marbles(dp)

    UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...

  9. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

随机推荐

  1. pip卡住不动的解决方案

    用的是anaconda2,也就是python在windows下的最好的一键安装包,有numpy scipy matplotlib等常用包预装好了 最近搞caffe的python接口,需要装protob ...

  2. Jenkins 2.x新建节点配置(Windows)

    2.0版本以上默认加入了权限插件,所以在进入主界面时是需要登录的. 一.主界面->[系统管理]->[管理节点]->[新建节点],进行节点的添加: 二.输入节点名称,已经选择[Perm ...

  3. 几个容易被忽略的mysql知识

    为什么标题要起这个名字呢?commen sence指的是那些大家都应该知道的事情,但往往大家又会会略这些东西,或者对这些东西一知半解,今天我总结下自己在mysql中遇到的一些commen sense类 ...

  4. Why TestNG?

    最近计划将工程中的单元测试从JUnit迁移到TestNG上面. Why TestNG(http://kaczanowscy.pl/tomek/sites/default/files/testng_vs ...

  5. A.Kaw矩阵代数初步学习笔记 10. Eigenvalues and Eigenvectors

    “矩阵代数初步”(Introduction to MATRIX ALGEBRA)课程由Prof. A.K.Kaw(University of South Florida)设计并讲授. PDF格式学习笔 ...

  6. django写的留言板

    代码见 https://github.com/linux-wang/show-me-the-code/tree/master/dj_test 实际上是 https://github.com/linux ...

  7. Java线程池的那些事

    熟悉java多线程的朋友一定十分了解java的线程池,jdk中的核心实现类为java.util.concurrent.ThreadPoolExecutor.大家可能了解到它的原理,甚至看过它的源码:但 ...

  8. Alpha版本十天冲刺——Day 3

    站立式会议 会议总结 队员 今天完成 遇到的问题 明天要做 感想 鲍亮 Android端登录验证接口 子线程无法返回从服务器获取的信息. 注册接口.忘记密码接口 开发经验不足,有一个问题不知道怎么解决 ...

  9. 【Alpha版本】 第九天 11.17

    一.站立式会议照片: 二.项目燃尽图: 三.项目进展: 成 员 昨天完成任务 今天完成任务 明天要做任务 问题困难 心得体会 胡泽善 完成我要应聘的详情显示,解决头像不能显示的问题,完成了报名及取消操 ...

  10. struts2校验总结

    struts校验框架提供两种校验:客户端校验和服务端校验.它们都是主要检查浏览器输入数据是否合法的校验器. 服务端校验 服务端校验是在服务器上检查输入数据,它的实现方法是重写validate()方法. ...