#include<iostream>
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
long long shu[100010],fu[100010];
int main()
{
int t,n,i,r=-1,l=100010;
cin>>n;
for(i=0;i<n;i++)
{
cin>>t;
shu[t]++;
l=min(l,t);
r=max(r,t);
}
fu[1]=1*shu[1];
for(i=max(l,2);i<=r;i++)
fu[i]=max(fu[i-1],fu[i-2]+shu[i]*i);
//前i个数(包含i)所能得到的最大分数等于,前i-1个数所能得到的最大分数。和选择第i个数所能得到的最大分数
//它们俩的最大值
cout<<fu[r];
}
相关文章
- 05-01Codeforces Round #336 (Div. 2) C. Chain Reaction set维护dp
- 05-01Codeforces Round #346 (Div. 2) G. Fence Divercity dp
- 05-01Codeforces Round #524 (Div. 2) C. Masha and two friends
- 05-01Codeforces Round #635 (Div. 2) E——Kaavi and Magic Spell 区间dp
- 05-01Codeforces Round #394 (Div. 2) C. Dasha and Password 暴力
- 05-01Codeforces Round #127 (Div. 1) C. Fragile Bridges dp
- 05-0101背包 Codeforces Round #267 (Div. 2) C. George and Job
- 05-01C. Moamen and XOR[Codeforces Round #737 (Div. 2)]
- 05-01Codeforces Round #379 (Div. 2) C. Anton and Making Potions 二分
- 05-01Codeforces Round #379 (Div. 2) C. Anton and Making Potions —— 二分