大意: 给定序列$a$, 每次任选$a_i$删除, 得分$min(a_{i-1},a_{i+1})$(无前驱后继时不得分), 求最大得分.

若一个数$x$的两边都比$x$大直接将$x$删除, 最后剩余一个先增后减的序列, 然后按从大到小顺序删除

#include <iostream>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <vector>
#include <string.h>
#include <queue>
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define REP(i,a,n) for(int i=a;i<=n;++i) using namespace std;
const int N = 2e6+10;
int a[N], b[N], f[N], n, m, k;
int q[N]; int main() {
scanf("%d", &n);
REP(i,1,n) scanf("%d", a+i);
ll ans = 0;
REP(i,1,n) {
while (*q>1&&q[*q]<=a[i]&&q[*q]<=q[*q-1]) {
ans += min(q[--*q], a[i]);
}
q[++*q] = a[i];
}
sort(q+1,q+1+*q);
REP(i,1,*q-2) ans += q[i];
printf("%I64d\n", ans);
}

Artem and Array CodeForces - 442C (贪心)的更多相关文章

  1. Maxim and Array CodeForces - 721D (贪心)

    大意: 给定序列, 每次操作选择一个数+x或-x, 最多k次操作, 求操作后所有元素积的最小值 贪心先选出绝对值最小的调整为负数, 再不断选出绝对值最小的增大它的绝对值 #include <io ...

  2. codeforces 442C C. Artem and Array(贪心)

    题目链接: C. Artem and Array time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  3. Codeforces 442C Artem and Array(stack+贪婪)

    题目连接:Codeforces 442C Artem and Array 题目大意:给出一个数组,每次删除一个数.删除一个数的得分为两边数的最小值,假设左右有一边不存在则算作0分. 问最大得分是多少. ...

  4. Codeforces 442C Artem and Array (看题解)

    Artem and Array 经过分析我们能发现, 如果对于一个a[ i ] <= a[ i + 1 ] && a[ i ] <= a[ i - 1 ]可以直接删掉. 最 ...

  5. cf442C Artem and Array

    C. Artem and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. Greg and Array CodeForces 296C 差分数组

    Greg and Array CodeForces 296C 差分数组 题意 是说有n个数,m种操作,这m种操作就是让一段区间内的数增加或则减少,然后有k种控制,这k种控制是说让m种操作中的一段区域内 ...

  7. Codeforces 442C

    题目链接 C. Artem and Array time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  8. codeforces 442C C. Artem and Array(有深度的模拟)

    题目 感谢JLGG的指导! 思路: //把数据转换成一条折线,发现有凸有凹 //有凹点,去掉并加上两边的最小值//无凹点,直接加上前(n-2)个的和(升序)//数据太大,要64位//判断凹与否,若一边 ...

  9. Codeforces 754A Lesha and array splitting(简单贪心)

    A. Lesha and array splitting time limit per test:2 seconds memory limit per test:256 megabytes input ...

随机推荐

  1. First Steps: Command-line

    This brief tutorial will teach how to get up and running with the Flyway Command-line tool. It will ...

  2. C++中的string常用函数用法

    标准c++中string类函数介绍   注意不是CString 之所以抛弃char*的字符串而选用C++标准程序库中的string类,是因为他和前者比较起来,不必 担心内存是否足够.字符串长度等等,而 ...

  3. html 之 img hspace 和 vspace 属性

    案例<img src="w3school.gif" hspace="30" vspace="30" /> 描述 通常图形浏览器不 ...

  4. 6、nginx的反向代理及缓存功能

    nginx模块的应用 ngx_http_proxy_module  nginx 反向代理模块: http://nginx.org/en/docs/http/ngx_http_proxy_module. ...

  5. 关于set和map迭代器支持的运算

    问题: 曾经想遍历一个set遍历.当时是这样写的: set<int>::iterator b = a.begin()+1 后来发现程序报错.究其原因是,set迭代器不支持加减数操作. 查看 ...

  6. Spring-json依赖

    <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jacks ...

  7. 转一篇 ShaderVariantCollection介绍的比较详细的文章 感谢作者

    http://www.seven-fire.cn/archives/174 Unity3D Shader加载时机和预编译 焱燚(七火)  |    2016年7月6日  |   UnityShader ...

  8. Educational Codeforces Round 3 D. Gadgets for dollars and pounds 二分+前缀

    D. Gadgets for dollars and pounds time limit per test 2 seconds memory limit per test 256 megabytes ...

  9. 网页title左边显示网页的logo图标

    打开某一个网页会在浏览器的标签栏处显示该网页的标题和图标,当网页被添加到收藏夹或者书签中时也会出现网页的图标,怎么在网页title左边显示网页的logo图标呢? 方法1: 找一个或者作一个ico文件, ...

  10. python中的3目运算(3元表达式)

    js中   ret  = 1 == 1 ? 'true' : 'false' python中   ret = 'true' if 1==1 else 'false'