Codeforces 442C Artem and Array(stack+贪心)
来源:互联网 发布:python scapy 抓包 编辑:程序博客网 时间:2024/05/21 23:00
题目连接:Codeforces 442C Artem and Array
题目大意:给出一个数组,每次删除一个数,删除一个数的得分为两边数的最小值,如果左右有一边不存在则算作0分。问最大得分是多少。
解题思路:首先将连续的a,b,c,a > b && c > b的情况将c掉,获得min(a,b)分,这样处理后数组变成一个递増再递减的序列,除了最大和第二大的取不到,其他数字均可以得分。
样例:4 10 2 2 8
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long ll;const int N = 5 * 1e5 + 5;int n, c = -1;ll stack[N];int main () { ll x, ans = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%lld", &x); while (c > 0 && stack[c-1] >= stack[c] && stack[c] < x) { ans += min(stack[c-1], x); c--; } stack[++c] = x; } sort (stack, stack + c + 1); for (int i = 0; i <= c - 2; i++) ans += stack[i]; printf("%lld\n", ans); return 0;}
2 1
- Codeforces 442C Artem and Array(stack+贪心)
- CodeForces 442C Artem and Array(贪心)
- codeforces 669C Little Artem and Matrix
- cf442C Artem and Array
- Codeforces #669 Div2 C. Little Artem and Matrix(模拟)
- codeforces#348-C. Little Artem and Matrix-模拟
- CodeForces 669C Little Artem and Matrix(暴力)
- Codeforces 669C Little Artem and Matrix (模拟)
- CodeForces 668C Little Artem and Random Variable(数学)
- CodeForces 641C Little Artem and Dance (模拟)
- Codeforces 669C Little Artem and Matrix【思维+暴力】
- CodeForces 641 C.Little Artem and Dance(水~)
- Codeforces Round #348 (div 2) C. Little Artem and Matrix
- Codeforces Round #253 (Div. 2) E. Artem and Array (思维)
- Codeforces 596B Wilbur and Array 【贪心】
- CodeForces 596B Wilbur and Array 贪心
- codeforces#331-B. Wilbur and Array-贪心
- Codeforces 721D Maxim and Array[贪心]
- 如何安全的终止java线程
- 深入研究Windows内部原理系列
- MyEclipse和Eclipse下安装XFire插件CXF插件 WebService
- SQLite学习手册(目录)
- Win8系统下完美手工删除ORACLE11G
- Codeforces 442C Artem and Array(stack+贪心)
- Catalan数计算及应用
- SQLite学习手册(目录)
- RSA加密和解密的完整过程
- 诺德外汇NordFX怎么开户,开户教程
- Oracle创建删除用户、角色、表空间、导入导出命令总结
- 在Eclipse环境下配置XDebug调试PHP代码
- mysql之avg(),count(),min()/max(),sum()函数
- 【索引】Codeforces Round #253 (Div. 2)