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 题解:这道题初看有点吓人,一开始居然想到要用全排序,没错我 ...
随机推荐
- android HttpClient将数据提交到服务器
1.HttpClient 使用方式 public static String loginByClientGet(String username,String password) { try { //打 ...
- resolution will not be reattempted until the update interval of repository-group has elapsed or updates are forced
Failed to execute goal on project safetan-web: Could not resolve dependencies for project com.safeta ...
- xcode查找当前程序的沙盒
随意在程序中添加一个断点,当程序命中断点的时候,控制台中会出现一个"lldb" 此时在"lldb"后面添加上 po NSHomeDirectory() 回车 ...
- slf4j的简单用法以及与log4j的区别
之前在项目中用的日志记录器都是log4j的日志记录器,可是到了新公司发现都是slf4j,于是想着研究一下slf4j的用法. 注意:每次引入Logger的时候注意引入的jar包,因为有Logger的包太 ...
- oracle里的tns是什么意思
参考http://www.jb51.net/article/44668.htm TNS简要介绍与应用 Oracle中TNS的完整定义:transparence Network Substrate透明网 ...
- nginx入门一
配置文件: server_name user root; worker_processes 2; error_log logs/error-test.log; #pid logs/nginx.pid; ...
- Ubuntu/Debian 微信安装
1. 更新系统 $ sudo apt-get update $ sudo apt-get install git-core curl build-essential openssl libssl-de ...
- mac使用influxdb和grafana
mac使用influxdb和grafana influxdb安装以及配置 brew update brew install influxdb ln -sfv /usr/local/opt/influx ...
- maven项目提示web.xml is missing或红色感叹号
1.web.xml is missing and <failOnMissingWebXml> is set to true 提示信息应该能看懂.也就是缺少了web.xml文件,<fa ...
- Java快速学习笔记01
这一波快速学习主要是应付校招笔面试用,功利性质不可避免. 学习网址: http://www.runoob.com/java/java-tutorial.html 执行命令解析: 以上我们使用了两个命令 ...