/* created by chjshen, date: 2024-12-26 08:53 */
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
const int N = 2E4 + 5;
int n, a[N];
int f[N];
int cnt, to[N];
void handle(void)
{
    // 2 3 4
    f[1] = to[a[1]] * a[1];
    if (a[2] == a[1] + 1)
    {
        f[2] = max(a[1] * to[a[1]], a[2] * to[a[2]]);
    }
    else
        f[2] = a[1] * to[a[1]] + a[2] * to[a[2]];
    for (int i = 3; i <= cnt; i++)
    {
        if (a[i] == a[i - 1] + 1)
        {
            f[i] = max(f[i - 1], f[i - 2] + a[i] * to[a[i]]);
        }
        else
            f[i] = f[i - 1] + a[i] * to[a[i]];
    }
    cout << f[cnt] << endl;
}
void initInput(void)
{
    ios::sync_with_stdio(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        to[a[i]]++;
    }
    sort(a + 1, a + n + 1);
    cnt = unique(a + 1, a + n + 1) - a - 1;
}
int main(void)
{
    initInput();
    handle();
    return 0;
}


0 条评论

目前还没有评论...