Boredom

A.Boredom

A.Boredom

time limit per test: 1 second
每次测试的时间限制:1秒

memory limit per test:256 megabytes
每次测试的内存限制:256兆字节

input: standard input
输入:标准输入

output: standard output
产出:标准产出

Alex doesn’tlike boredom.Thats 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
给定由n个整数组成的序列a。玩家可以做几个步骤。在一个步骤中,他可以选择

sequence (lets denote ita;) and delete it, at that allelements equal to ag+1 and a;- 1 also must be deleted from the sequence.That step
序列(让我们表示Ita;)并删除它,在所有元素中等于ag+1和a;-1也必须从序列中删除。

brings ag points to the player.
给玩家带来点银点。

Alex is a perfectionist, so he decided to get as many points as possible.Help him.
亚历克斯是一个完美主义者,所以他决定得到尽可能多的分数,帮助他。

lnput
输入

The first line contains integer n(1 第一行包含整数n(1

The second line contains n integers a1,a2,…an(1≤a;105)
第二行包含n个整数A1,a2,.an(1≤a;105)

output
输出量

Print a single integer -the maximum number of points that Alex can earn.
打印一个整数-亚历克斯可以赚取的最大点数。

线性dp
d[i]=max{d[i-1],d[i-2]+i*a[i]}

int a[100001] = {0}, b[100002];
int main()
{
	int n,k;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin>>k;
		++a[k];
	}
	b[1] = a[1];
	for (int i = 2; i <= n; ++i)
	{
		b[i] = b[i - 1]> b[i - 2] + i * a[i]? b[i - 1] : b[i - 2] + i * a[i];
	}
	cout << b[100002] << endl;
	return 0;
}

你可能感兴趣的:(cf)