题目连接: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;
}

版权声明:本文博客原创文章。博客,未经同意,不得转载。

Codeforces 442C Artem and Array(stack+贪婪)的更多相关文章

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

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

  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. cf442C Artem and Array

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

  4. Codeforces Round #504 D. Array Restoration

    Codeforces Round #504 D. Array Restoration 题目描述:有一个长度为\(n\)的序列\(a\),有\(q\)次操作,第\(i\)次选择一个区间,将区间里的数全部 ...

  5. Codeforces 442C

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

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

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

  7. Artem and Array CodeForces - 442C (贪心)

    大意: 给定序列$a$, 每次任选$a_i$删除, 得分$min(a_{i-1},a_{i+1})$(无前驱后继时不得分), 求最大得分. 若一个数$x$的两边都比$x$大直接将$x$删除, 最后剩余 ...

  8. Educational Codeforces Round 11A. Co-prime Array 数学

    地址:http://codeforces.com/contest/660/problem/A 题目: A. Co-prime Array time limit per test 1 second me ...

  9. CodeForces - 86D D. Powerful array —— 莫队算法

    题目链接:http://codeforces.com/problemset/problem/86/D D. Powerful array time limit per test 5 seconds m ...

随机推荐

  1. iOS开发- Xcode插件(一)-规范凝视生成器VVDocumenter

    分享几个经常使用的Xcode插件. 第一个, 规范凝视生成器VVDocumenter. 顾名思义, 它能够非常方便的为你自己主动加入�凝视 使用效果例如以下: 下载链接:https://github. ...

  2. ubuntu 下搭建apache+python的运行环境

    ubuntu下怎么搭建apache+python运行环境,可以参考http://www.01happy.com/ubuntu-apache-mod-python/ ,这里只是简单的记录下步骤,本文主要 ...

  3. httpclient 文件上传

    /**      * 上传文件      */     public static Boolean  uploadFile(String fileName, String url) {         ...

  4. Android 建立View 圆角

    虽然很easy,不过还是录制. 混合参观 在drawable文件下 创建一个布局文件corners_bg.xml <?xml version="1.0" encoding=& ...

  5. Android 常规任务的高度【schedule】与【scheduleAtFixedRate】差额

    于android计划定期任务有两种方法 1.schedule 2.scheduleAtFixedRate 这两种方法的差别在于 首次调用时间(Date when)这个參数 <span style ...

  6. Java 启动线程的方式

    面试题:JAVA启动线程的方式有哪些? 1.继承Thread [java] view plaincopy public class java_thread extends Thread{ public ...

  7. SQL Server 2008性能故障排查(二)——CPU

    原文:SQL Server 2008性能故障排查(二)--CPU 承接上一篇:SQL Server 2008性能故障排查(一)--概论 说明一下,CSDN的博客编辑非常不人性化,我在word里面都排好 ...

  8. 超过lua上帝的语言

    上帝的语言(god)它是基于lua和RPP新一代编程语言 为什么需要它? 1.好多人不喜欢lua语法,god的语法更像C 2.god支持元编程.闭包.协程 3.凡是lua支持的特性god也支持,lua ...

  9. iOS kvc

    kvc在我的脑海里用来更改属性的实例变量值. 今天,他们遇到了kvc第二次去学习它,在网上看了很多博客,这似乎不符合我的口味,为了提取一些以下的.总结自己的. http://www.cnblogs.c ...

  10. Swing 显示良好JPanel保存为图片

    在JFrame例如,下面的代码被添加 //自己的JPanel DrawPanel drawPanel = new DrawPanel(list, width, height, start, end); ...