Codeforces 442C Artem and Array (看题解)
经过分析我们能发现, 如果对于一个a[ i ] <= a[ i + 1 ] && a[ i ] <= a[ i - 1 ]可以直接删掉。
最后剩下一个先增后减的序列, 除了最大的两个都能加上。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 5e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); int n, a[N], que[N], top;
LL ans;
int main() {
scanf("%d", &n);
for(int i = ; i <= n; i++) scanf("%d", &a[i]);
que[++top] = a[];
for(int i = ; i <= n; i++) {
while(top > && que[top] <= que[top - ] && que[top] <= a[i]) {
ans += min(que[top - ], a[i]);
top--;
}
que[++top] = a[i];
}
sort(que + , que + + top);
for(int i = ; i <= top - ; i++) ans += que[i];
printf("%lld\n", ans);
return ;
} /*
*/
Codeforces 442C Artem and Array (看题解)的更多相关文章
- Codeforces 442C Artem and Array(stack+贪婪)
题目连接:Codeforces 442C Artem and Array 题目大意:给出一个数组,每次删除一个数.删除一个数的得分为两边数的最小值,假设左右有一边不存在则算作0分. 问最大得分是多少. ...
- Codeforces 1017F The Neutral Zone (看题解)
这题一看就筛质数就好啦, 可是这怎么筛啊, 一看题解, 怎么会有这么骚的操作. #include<bits/stdc++.h> #define LL long long #define f ...
- Codeforces 513E2 Subarray Cuts dp (看题解)
我们肯定要一大一小间隔开来所以 把式子拆出来就是类似这样的形式 s1 - 2 * s2 + 2 * s3 + ...... + sn 然后把状态开成四个, 分别表示在顶部, 在底部, 在顶部到底部的中 ...
- Codeforces 822E Liar dp + SA (看题解)
Liar 刚开始感觉只要开个dp[ i ][ j ][ 0 / 1 ]表示处理了s的前 i 个用了 k 段, i 是否是最后一段的最后一个字符 的 t串最长匹配长度, 然后wa24, 就gg了.感觉这 ...
- Codeforces 196E Opening Portals MST (看题解)
Opening Portals 我们先考虑如果所有点都是特殊点, 那么就是对整个图求个MST. 想在如果不是所有点是特殊点的话, 我们能不能也 转换成求MST的问题呢? 相当于我们把特殊点扣出来, 然 ...
- Codeforces 725E Too Much Money (看题解)
Too Much Money 最关键的一点就是这个贪心可以在sqrt(n)级别算出答案. 因为最多有sqrt(n)个不同的数值加入. 我们可以发现最优肯定加入一个. 然后维护一个当前可以取的最大值, ...
- codeforces 442C C. Artem and Array(贪心)
题目链接: C. Artem and Array time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Codeforces 750E New Year and Old Subsequence 线段树 + dp (看题解)
New Year and Old Subsequence 第一感觉是离线之后分治求dp, 但是感觉如果要把左边的dp值和右边的dp值合起来, 感觉很麻烦而且时间复杂度不怎么对.. 然后就gun取看题解 ...
- Codeforces Round #668 (Div. 2)A-C题解
A. Permutation Forgery 题目:http://codeforces.com/contest/1405/problem/A 题解:这道题初看有点吓人,一开始居然想到要用全排序,没错我 ...
随机推荐
- Ubuntu下提示U盘没有权限--只能读不能写
在Windows下,U盘能够正常地读写文件(能复制粘贴),但发现有个文件打不开.然后在Linux下,对U盘只能读不能写.提示:Read only system. 参考:https://bugs.lau ...
- Bootstrap -- 文件上传插件File Input的使用
BootstrapFileInput下载参考:http://www.jq22.com/jquery-info5231 网友经验参见:http://www.cnblogs.com/wuhuacong/p ...
- 【通信】Jave代码中生成url http请求
/** * 向指定 URL 发送POST方法的请求 * * @param url * 发送请求的 URL * @param param * 请求参数,请求参数应该是 name1=value1& ...
- mysql数据库导出excel xml等格式文件
http://jingyan.baidu.com/article/ac6a9a5e43a62e2b653eac83.html
- Linux查找文件、文件夹
https://www.jianshu.com/p/f3a46e5c96ba 查找目录:find /(查找范围) -name '查找关键字' -type d 查找文件:find /(查找范围) -na ...
- Java 集合和映射表
集合 可以使用集合的三个具体类HashSet.LinkedHashSet.TreeSet来创建集合 HashSet类 负载系数 当元素个数超过了容量与负载系数的乘积,容量就会自动翻倍 HashSet类 ...
- weblogic基本目录介绍,位数查看,启动与发布项目,修改JVM参数,设置项目为默认项目
这里的基本目录%base%表示安装目录,如我的目录为:E:/weblogic就是%base% 1.weblogic目录介绍 weblogic主要的目录介绍: 1.日志目录: 每个domain(域)都有 ...
- spring整合ehcache2.5.2缓存异常-- net.sf.ehcache.CacheException
报错如下: The source of the existing CacheManager is: DefaultConfigurationSource [ ehcache.xml or ehcach ...
- Linux系统7z文件解压
获取p7zip_16.02_src_all.tar.bz2 1.解压 tar jxvf p7zip_16.02_src_all.tar.bz2 2.编译 cd p7zip_16.02 make &am ...
- Java SSH远程执行Shell命令、shell脚本实现(Ganymed SSH)
jar包下载地址: http://www.ganymed.ethz.ch/ssh2/ 此源码的好处就是没有依赖很多其他的包,拷贝过来干干净净.具体代码实现可以看下文,或参考官方文档,在下载的压缩包里g ...