CSU1350 To Add which?
题目链接:
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1350
这题目因为每一个数都跟相邻的数有关,所以可以从左到右和从右到左一次扫一遍即可
代码:
#include<iostream>
#include<cstdio>
#define M 100100
using namespace std; int num[M],Max[M],Min[M]; int max(int a,int b)
{
return a>b?a:b;
}
int main()
{
int T,n,D;
long long ans;
cin>>T;
while(T--){
ans=;
cin>>n>>D;
for(int i=;i<n;i++) cin>>num[i]; Max[]=num[];
for(int i=;i<n;i++)
{
if(Max[i-]-num[i]>D)
Max[i]=Max[i-]-D;
else Max[i]=num[i];
} Min[n-]=num[n-];
for(int i=n-;i>=;i--)
{
if(Min[i+]-num[i]>D)
Min[i]=Min[i+]-D;
else Min[i]=num[i];
} for(int i=;i<n;i++) ans+=(max(Min[i],Max[i])-num[i]);
cout<<ans<<endl;
}
return ;
}
CSU1350 To Add which?的更多相关文章
- 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 ...
- EntityFramework Core 1.1 Add、Attach、Update、Remove方法如何高效使用详解
前言 我比较喜欢安静,大概和我喜欢研究和琢磨技术原因相关吧,刚好到了元旦节,这几天可以好好学习下EF Core,同时在项目当中用到EF Core,借此机会给予比较深入的理解,这里我们只讲解和EF 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 ...
- [转]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 ...
- [deviceone开发]-动态添加组件add方法的示例
一.简介 这个示例详细介绍ALayout的add方法的使用(原理也适用于Linearlayout),以及add上去的新ui和已有的ui如何数据交换,初学者推荐.二.效果图 三.相关下载 https:/ ...
- [LeetCode] Add Two Numbers II 两个数字相加之二
You are given two linked lists representing two non-negative numbers. The most significant digit com ...
- [LeetCode] Add Strings 字符串相加
Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2. ...
- [LeetCode] Expression Add Operators 表达式增加操作符
Given a string that contains only digits 0-9 and a target value, return all possibilities to add ope ...
- [LeetCode] Add Digits 加数字
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. ...
随机推荐
- 17984 FFF团的怒火
17984 FFF团的怒火 该题有题解 时间限制:1000MS 内存限制:65535K提交次数:55 通过次数:3 收入:3 题型: 编程题 语言: G++;GCC;VC;JAVA Descri ...
- Keepalived+LVS(DR)+MySQL
实验环境 主机名 IP VIP 服务 主备 KA_LV_MYSQL_01 192.168.30.130 192.168.30.100 keepalived.LVS.MySQL MASTER KA_LV ...
- Suricata的总体架构
Suricata的总体架构 报文检测系统通常四大部分,报文获取.报文解码.报文检测.日志记录:suricata不同的功能安装模块划分,一个模块的输出是另一个模块的输入,suricata通过线程将模块 ...
- AJPFX总结jvm运行时内存分布
jvm的运行过程中将java程序运行时数据区分为以下几个部分: (1)程序计数器:存储虚拟机字节码执行的地址 (2)java虚拟机栈:java方法运行时的局部变量表,操作数栈,方法出口等 ( ...
- iOS 解决iOS 9下的http请求发送失败问题
iOS9中 因为系统要求所有的请求都必须使用https, 所以发送http请求会失败,如果想让程序能够兼容http请求 在info.plist中添加以下代码: 这里需要做的是右键info.plist文 ...
- 《Python基础教程》 读书笔记 第六章 抽象 函数 参数
6.1创建函数 函数是可以调用(可能包含参数,也就是放在圆括号中的值),它执行某种行为并且返回一个值.一般来说,内建的callable函数可以用来判断函数是否可调用: >>> x=1 ...
- ASP.NET Core 企业级开发架构简介及框架汇总 (转载)
ASP.NET Core 企业开发架构概述 企业开发框架包括垂直方向架构和水平方向架构.垂直方向架构是指一个应用程序的由下到上叠加多层的架构,同时这样的程序又叫整体式程序.水平方向架构是指将大应用分成 ...
- C#读取web.config配置文件内容
1.对配置文件的访问. 方法一: string myConn =System.Configuration.ConfigurationManager.ConnectionStrings["sq ...
- ubuntu破解密码方法
摘要: 开机按住任何键(shift)停住grub菜单,进入advanced option for ubuntu,出现的菜单中,光标移动至…(recovery mode)按E进入编辑,找到ro reco ...
- Elasticsearch搜索含有数字标签的处理
{"tag_id":“12345”} 在search的时候是完全匹配,因为Elasticsearch在处理这个的过程中把“123456”字符当成一个整体的数据,因此折腾了好久就是找 ...