题目链接:Codeforces 455A Boredom
题目大意:给定一个序列,每次从序列中选中一个数ak,获得ak的得分,同时删除序列中所有的ak−1,ak+1,求最大得分。
解题思路:开一个数组记录各个数有多少个,然后遍历一遍 ,维护两个值,一个是前一个不选的最大值,一个是前一个选的最大值。hack点,爆int了。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
int n, arr, c[maxn];
int main () {
cin >> n;
memset(c, 0, sizeof(c));
for (int i = 0; i < n; i++) {
cin >> arr;
c[arr]++;
}
ll p = 0, q = 0;
for (int i = 1; i < maxn; i++) {
ll tmp = q + 1LL * i * c[i];
q = max(p, q);
p = tmp;
}
cout << max(p, q) << endl;
return 0;
}
分享到:
相关推荐
Codeforces 185A - Plant 全测试点49个
Codeforces 题库 101-200 共~500题 codeforces.com版权所有。 程序可提交至该网站评测。
Codeforces 题库 001-100 共~500题 codeforces.com版权所有。 程序可提交至该网站评测。
codeforces编程网站预测分数插件
使用于Google Chrome的Codeforces Enhancer 1.1.2插件安装包。 版本:codeforces enhancer 1.1.2 使用浏览器:Google Chrome
codeforces 19 E Fairy 一道比较难的题目的解题报告 推荐阅读
Codeforces global round 10 codes
Codeforces round 678 division 2 codes
Some of the Codeforces problems codes
lucifer1004大佬的博客cf上分攻略故里大佬的githubcf思维题刷题数:44- (1421)codeforces 676 div2 A,B done
Codeforces round 678 D2_Codeforces_源码
一个Codeforces、牛客竞赛、AtCoder平台的编程竞赛查询插件,ACMer必备.zip
打codeforces的神器
codeforces-js Codeforces JS
Codeforces Round #723 (Div. 2).md
使用 C# + WPF 开发 --- 还在发愁打了那么多场比赛都没有进入首页么? 还在为了前 5 的 hacker 名额阅读千份代码么? 是的,你没有看错! 这是一个 Edu & Div.3 轮 Open hacking 错误代码自动查找器!...
接受串子-接受字符串相等-接受Codeforces回合#684(Div.2) 2/6 1440A-购买琴弦-接受1440B -中位数的总和-已接受1440C1-二进制表(简易版)-已接受1440C2-二进制表(硬版)-已接受 Codeforces回合#683(分区2) 1/...
codeforces算法比赛题:1295A题
[codeforces 1304A] Two Rabbits 整除+模 总目录详见https://blog.csdn.net/mrcrack/article/details/103564004 在线测评地址https://codeforces.ml/contest/1304/problem/A Problem Lang Verdict Time Memory ...
PDF-CodeForces问题 PDF文件中的CodeForces问题 利用CodeForces提取在这个库中的文件 ,文件夹名代表来自CodeForces网址contests`的ID,每个文件夹包含比赛的问题。 有关CodeForces竞赛的疯狂事实 CodeForces上有937...