这个题目其实很简单,可惜当时比赛的时候看到出的人少,以为有trick,就和队友扯淡去了;

因为每个数总是被相邻的数影响,所以往前往后扫两遍就行了;

 #include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 100005
using namespace std; int num[maxn];
int num1[maxn];
int num2[maxn]; int main()
{
int t;
int n,d;
scanf("%d",&t);
while(t--)
{
long long ans=;
scanf("%d%d",&n,&d);
for(int i=;i<n;i++)
{
scanf("%d",&num[i]);
}
num1[]=num[];
num2[n-]=num[n-];
for(int i=;i<n;i++)
{
if(num1[i-]-num[i]>d)
num1[i]=num1[i-]-d;
else num1[i]=num[i];
}
for(int i=n-;i>=;i--)
{
if(num2[i+]-num[i]>d)
num2[i]=num2[i+]-d;
else num2[i]=num[i];
}
for(int i=;i<n;i++)
{
ans+=max(num1[i],num2[i])-num[i];
}
printf("%lld\n",ans);
}
return ;
}

csuoj 1350: To Add Which?的更多相关文章

  1. 1350: To Add Which? (优先队列+贪心 或者 数组模拟)

    1350: To Add Which? Submit Page    Summary    Time Limit: 1 Sec     Memory Limit: 128 Mb     Submitt ...

  2. 中南大学第一届长沙地区程序设计邀请赛 To Add Which?

    1350: To Add Which? Time Limit: 1 Sec  Memory Limit: 128 MB Description There is an integer sequence ...

  3. HDU 1350

    http://acm.hdu.edu.cn/showproblem.php?pid=1350 给m个顾客的乘车信息,表示几点前上车,要从一个坐标点到达另一个坐标点,花费的时间是两点的曼哈顿距离,两次换 ...

  4. AutoMapper:Unmapped members were found. Review the types and members below. Add a custom mapping expression, ignore, add a custom resolver, or modify the source/destination type

    异常处理汇总-后端系列 http://www.cnblogs.com/dunitian/p/4523006.html 应用场景:ViewModel==>Mode映射的时候出错 AutoMappe ...

  5. EntityFramework Core 1.1 Add、Attach、Update、Remove方法如何高效使用详解

    前言 我比较喜欢安静,大概和我喜欢研究和琢磨技术原因相关吧,刚好到了元旦节,这几天可以好好学习下EF Core,同时在项目当中用到EF Core,借此机会给予比较深入的理解,这里我们只讲解和EF 6. ...

  6. ASP.NET Core: You must add a reference to assembly mscorlib, version=4.0.0.0

    ASP.NET Core 引用外部程序包的时候,有时会出现下面的错误: The type 'Object' is defined in an assembly that is not referenc ...

  7. [转]NopCommerce How to add a menu item into the administration area from a plugin

    本文转自:http://docs.nopcommerce.com/display/nc/How+to+code+my+own+shipping+rate+computation+method Go t ...

  8. [deviceone开发]-动态添加组件add方法的示例

    一.简介 这个示例详细介绍ALayout的add方法的使用(原理也适用于Linearlayout),以及add上去的新ui和已有的ui如何数据交换,初学者推荐.二.效果图 三.相关下载 https:/ ...

  9. [LeetCode] Add Two Numbers II 两个数字相加之二

    You are given two linked lists representing two non-negative numbers. The most significant digit com ...

随机推荐

  1. C#一些小知识点

    1. 在Load时候由代码来做控件PictureBox,并且用代码将图片加载进去: private void Form2_Load(object sender, EventArgs e) { Dire ...

  2. 聊聊css盒子模型

    css盒子模型原理: 在网页设计中常听的属性名:内容(content).填充/内边距(padding).边框(border).外边距(margin), CSS盒子模式都具备这些属性. 这些属性我们可以 ...

  3. 多个DIV让float:left属性,最后一个DIV填满剩余的部分

    <DIV style="border:1px solid red; overflow:hidden;zoom:1;">      <DIV style='floa ...

  4. 读取tomcat下的文件夹路径

    背景:测试的为了每次部署时清缓存,将temp文件夹也删了,导致系统中有些excel导出功能用不了. 解决:新建一个监听文件,在系统启动时,判断temp文件夹是否存在,不存在就新建. temp文件夹的作 ...

  5. linux process 相关命令

    1.显示指定用户信息:ps -u root 2.显示所有进程信息,连同命令行:ps -ef 3. ps 与grep 常用组合用法,查找特定进程:ps -ef|grep ssh 4. 把所有进程显示出来 ...

  6. 第二十七篇、使用MVVM布局页面

    思路:架构的设计模式主要有这么两种 >MVC :这种方式用得很多,也很是常见,不在过多的介绍 >MVVM:使用这种 常常需要导入第三方框架,常见的是响应式框架 >主要讲一下ViewM ...

  7. vue防止闪烁

    v-text也可以 转意的话使用v-html <style> [v-clock]{ display:none } <style> <span>{{msg}}< ...

  8. Java实战之03Spring-03Spring的核心之AOP(Aspect Oriented Programming 面向切面编程)

    三.Spring的核心之AOP(Aspect Oriented Programming 面向切面编程) 1.AOP概念及原理 1.1.什么是AOP OOP:Object Oriented Progra ...

  9. ceilometer

    控制节点: ceilometer-api: /etc/init.d/openstack-ceilometer-api  status ceilometer-collector /etc/init.d/ ...

  10. 循环/loop 结构/structure

    1.Shell loop 2.C++/CPlusPlus ①.std::for_each ②.for loop ③.Iterator library 3.Python Loop ①.Python.or ...