Div 1.455A - Boredom

思路

类似大盗阿福,就是价值变了一下。

记得开\(long~long\)(吼)

记得开\(long~long\)(吼)

记得开\(long~long\)(吼)

重要事情说三遍

代码

#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 100010;
int n;
LL cnt[N];
LL f[N];
int main () {
	cin >> n;
	for (int i = 1;i <= n;i++) {
		int x;
		cin >> x;
		cnt[x]++;
	}
	f[1] = cnt[1];
	for (int i = 2;i < N;i++) f[i] = max (f[i - 1],f[i - 2] + (cnt[i] ? i * cnt[i] : 0));
	cout << f[N - 1] << endl;
	return 0;
}
posted @ 2022-10-11 20:22  incra  阅读(25)  评论(0)    收藏  举报