题目描述 Description

  给定一个长度为n的数列{a1,a2...an},每次可以选择一个区间[l,r],使这个区间内的数都加一或者都减一。
  问至少需要多少次操作才能使数列中的所有数都一样,并求出在保证最少次数的前提下,最终得到的数列有多少种。

输入描述 Input Description

  第一行一个正整数n 
  接下来n行,每行一个整数,第i+1行的整数表示ai。

输出描述 Output Description

  第一行输出最少操作次数
  第二行输出最终能得到多少种结果

样例输入 Sample Input

4
1
1
2
2

样例输出 Sample Output

1
2

数据范围及提示 Data Size & Hint

  对于100%的数据,n=100000,0<=ai<2147483648。

/*
典型的差分题目
先做一个差分序列b,接下来就是怎么把除了b1之外的所有数都变成0,因为可以进行区间修改,那么对于序列b来说就是一个数加1的同时一个数减1,或一个数加1,或一个数减1。因为要求步数最少,所以要尽可能把加1用在负数上,把减1用在正数上,剩下的只有正数或负数时再单独加1或减1。至于方案数,取决于b1,那么我们要在不影响步数的情况下修改b1,那么只能把单独加1或减1换成修改b1和原来那个数。
*/
#include<cstdio>
#include<iostream>
#define M 100010
#define ll long long
using namespace std;
ll a[M],b[M];int n;
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
cin>>a[i];
b[i]=a[i]-a[i-];
}
ll tot1=,tot2=;
for(int i=;i<=n;i++)
if(b[i]>)tot1+=b[i];
else tot2-=b[i];
cout<<max(tot1,tot2)<<endl<<max(tot1-tot2,tot2-tot1)+;
return ;
}

IncDec Sequence(codevs 2098)的更多相关文章

  1. HDU 5860 Death Sequence(死亡序列)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  2. HDU 5783 Divide the Sequence(数列划分)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  3. HDU 1560 DNA sequence(DNA序列)

    HDU 1560 DNA sequence(DNA序列) Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K  ...

  4. 1085 Perfect Sequence (25 分)

    1085 Perfect Sequence (25 分) Given a sequence of positive integers and another positive integer p. T ...

  5. [PAT] 1140 Look-and-say Sequence(20 分)

    1140 Look-and-say Sequence(20 分)Look-and-say sequence is a sequence of integers as the following: D, ...

  6. 【BZOJ 3043】 3043: IncDec Sequence (差分)

    3043: IncDec Sequence Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 589  Solved: 332 Description 给 ...

  7. easyfinding(codevs 3280)

    3280 easyfinding  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description 给一个M 行N  列 ...

  8. (CodeForces - 5C)Longest Regular Bracket Sequence(dp+栈)(最长连续括号模板)

    (CodeForces - 5C)Longest Regular Bracket Sequence time limit per test:2 seconds memory limit per tes ...

  9. Bestcoder13 1003.Find Sequence(hdu 5064) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5064 题目意思:给出n个数:a1, a2, ..., an,然后需要从中找出一个最长的序列 b1, b ...

随机推荐

  1. 2016年4月7日 js的全选和反选

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title> ...

  2. 锋利的jQuery-4--动画方法总结简表

  3. pthread 学习系列 case2-- 使用互斥锁

    ref http://www.ibm.com/developerworks/cn/linux/thread/posix_thread1/index.html #include <pthread. ...

  4. Linux的一些基础

    想要知道你的 Linux 支持的文件系统有哪些,可以察看底下这个目录: [root@www ~]# ls -l /lib/modules/$(uname -r)/kernel/fs 系统目前已加载到内 ...

  5. 我所使用的一个通用的Makefile模板

    话不多说,请看: 我的项目有的目录结构有: dirls/ ├── include │   └── apue.h ├── lib │   ├── error.c │   ├── error.o │   ...

  6. Protocol Buffers介绍

    基本概念 Protocol Buffers(以下简称PB)是一种独立于语言.独立于开发平台.可扩展的序列化数据结构框架,它常常被用在通信.数据序列化保存等方面. PB是一种敏捷.高效.自动化的用于对数 ...

  7. Windows下tcp参数优化

    Windows系统下的TCP参数优化2013-04-25      0 个评论       作者:最初的幸福ever收藏     我要投稿Windows系统下的TCP参数优化 TCP连接的状态与关闭方 ...

  8. 【NGUI】grid下面的item的重复利用

    http://blog.csdn.net/u012091672/article/details/21159075解决的问题 使用grid放置item的时候,每次数据可能都不一样,但是每次都删除grid ...

  9. UIImagePickerController详解

    转载自:http://blog.csdn.net/kingsley_cxz/article/details/9157093 1.UIImagePickerController的静态方法: imagep ...

  10. UITableView 学习笔记

    http://www.cnblogs.com/smileEvday/archive/2012/06/28/tableView.html UITableView学习笔记 作者:一片枫叶 看TableVi ...