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. ...
随机推荐
- map,reduce高阶函数
iterator:迭代器 python的iterator是一个惰性序列(即你不主动去遍历它,他不会去计算其中元素的值) m是一个iterator,所以通过tuple()函数让整个序列计算出来,并返回一 ...
- position 位置、表单
一.position 位置 1.只要使用了定位,必须有一个相对的参照物 2.具体定位的那个元素需加position:absolute:(绝对的) 绝对的:就是具体到某一个地方,特别详细的意思 ...
- jQuery选择器之属性筛选选择器
在这么多属性选择器中[attr="value"]和[attr*="value"]是最实用的 [attr="value"]能帮我们定位不同类型 ...
- 正确使用MySQL JDBC setFetchSize()方法解决JDBC处理大结果
一直很纠结,Oracle的快速返回机制,虽然结果集很多,可是它能很快的显示第一个结果,虽然通过MYSQl的客户端可以做到,但是通过JDBC却不行. 今天用了1个多小时,终于搞定此问题,希望对广大Jav ...
- Android(java)学习笔记168:Activity 4 种启动模式
1. 任务栈(task stack): 任务栈 是用来记录用户操作的行为,维护一个用户体验. 一个应用程序一般都是由多个activity组成的. 任务栈(task stack)记录存放用户开启的act ...
- jeecms
===标签=== <!-- 显示一级栏目对应的二级栏目 --> <!-- [@cms_channel_list parentId=c.id] [#if tag_list?size&g ...
- 细说PHP-5.4 变量的类型
变量类型是指保存在该变量中的数据类型.计算机操作的对象是数据在计算编程语言世界里,每一个数据也都有它的类型,具有相同类型的数据才能彼此操作.例如书柜是装书用的.大衣柜是放衣服用的.保险柜是存放贵重物品 ...
- Proguard配置文件内容
-injars elec-bendao-1.2.jar-outjars elec-bendao-1.2-end.jar -libraryjars lib\charsets.jar-libraryjar ...
- springmvc @RequestParam @RequestBody @PathVariable 等参数绑定注解详解
简介: handler method 参数绑定常用的注解,我们根据他们处理的Request的不同内容部分分为四类:(主要讲解常用类型) A.处理requet uri 部分(这里指uri templat ...
- Shell数值比较
Shell数值比较 比较 描述 n1 -eq n2 检查n1是否与n2相等 n1 -ge n2 检查n1是否大于或等于n2 n1 -gt n2 检查n1是否大于n2 n1 -le n2 检查n1是否小 ...