http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4915题意:a[k]-一个任意的数,这个数要等于a[1]~a[k]每个数减去任意一个数,经过多次这样的变换到达目标b序列,能到达就yes不能到达距no思路:既然a[k]前面数相减等于这个数,则所有减去的数之和sum一定数偶数。其中最大的减数的2倍一定要小于这个sum,如果不满足就不可能从a序列到b序列。Gao The Sequence


Time Limit: 2 Seconds      Memory Limit: 65536 KB

You are given a sequence of integers, A1,A2,...,An. And you are allowed a manipulation on the sequence to transform the origin sequence into another sequence B1,B2,...,Bn(Maybe the two sequences are same ). The manipulation is specified as the following three steps:

1.Select an integer Ai and choose an arbitrary positive integer delta as you like.

2.Select some integers Aj satisfying j < i, let's suppose the selected integers are Ak1,Ak2,...,Akt , then subtract an arbitrary positive integer Di from Aki (1 ≤ i ≤ t) as long as sum(Di) = delta.

3.Subtract delta from Ai.

The manipulation can be performed any times. Can you find a way to transform A1,A2,...,An to B1,B2,...,Bn ?

Input

The input consist of multiple cases. Cases are about 100 or so. For each case, the first line contains an integer N(1 ≤ N ≤ 10000) indicating the number of the sequence. Then followed by N lines, ith line contains two integers Ai and Bi (0 ≤ Bi ≤ Ai ≤ 4294967296).

Output

Output a single line per case. Print "YES" if there is a certain way to transform Sequence A into Sequence B. Print "NO" if not.

Sample Input

3
3 2
4 2
5 2
3
2 0
7 1
3 1

Sample Output

YES
NO
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int max(int x,int y)
{
if(x>y)
return x;
else
return y;
}
int main()
{
long long maxn,a[10000],b[10000],sum,q;
int t,i;
while(~scanf("%d",&t))
{
sum=maxn=0;
for(i=0;i<t;i++)
{
scanf("%lld%lld",&a[i],&b[i]);
q=a[i]-b[i];
sum+=q;
maxn=max(maxn,q);
}
if(sum%2!=0)
printf("NO\n");
else if(2*maxn>sum)
printf("NO\n");
else
printf("YES\n"); }
return 0;
}
/*
6
10 1
5 3
16 5
9 3
9 2
14 1
*/

zoj 3672 Gao The Sequence的更多相关文章

  1. zoj Gao The Sequence

    Gao The Sequence Time Limit: 2 Seconds      Memory Limit: 65536 KB You are given a sequence of integ ...

  2. ZOJ 3408 Gao

    ZOJ题目页面传送门 给定一个有向图\(G=(V,E),n=|V|,m=|E|\)(可能有重边和自环,节点从\(0\)开始编号),以及\(q\)组询问,对于每组询问你需要回答有多少条从节点\(0\)开 ...

  3. ZOJ 3647 Gao the Grid dp,思路,格中取同一行的三点,经典 难度:3

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4837 三角形的总数=格子中任取3个点的组合数-同一横行任取3个点数目-同一纵行 ...

  4. zoj3672 Gao The Sequence

    原地踏步了半年,感觉一切都陌生了~ 题意:a[i]-一个任意的数,这个数要等于a[1]~a[i-1]每个数减去任意一个数,经过多次这样的变换到达目标b序列,能到达就yes不能到达距no. 一开始各种分 ...

  5. zoj 3672 思考题

    http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemId=4915 真是老了.脑子不会动了,可是事实上就算如今搜了题解A了,还是没总结出思 ...

  6. zoj 3647 Gao the Grid

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4837 先求出从所有点随机找出三个点的组合数,然后去掉共线的,平行好去掉,斜线就 ...

  7. Zoj 3535 Gao the String II (AC自己主动机+dp)

    题目大意: 用集合A中的串构造出一个串,使之让很多其它的setB中的串成为他的子串. 思路分析: 和 Codeforces 86C 几乎相同. 只是这里是要用A中的构造. 先用A 和 B的串构造一个自 ...

  8. 【ZOJ 4060】Flippy Sequence

    [链接] 我是链接,点我呀:) [题意] [题解] 按照两个区间的排列方式 我们可以分成以下几种情况 会发现这两个区间的作用 最多只能把两段连续不同的区间变为相同. 那么写个for处理出连续不相同的一 ...

  9. ZOJ 2421 Recaman's Sequence

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1421 题目大意: 定义a^m为 a^m = a^(m-1) - m  如果a^ ...

随机推荐

  1. 安卓数据存储(2):SharedPreferences

    SharedPreferences是Android中最容易理解的数据存储技术,实际上SharedPreferences处理的就是一个key-value(键值对)在读取数据时可以通过这个键把相应的值取出 ...

  2. sqlserver 时间 格式化

    0   或   100   (*)     默认值   mon   dd   yyyy   hh:miAM(或   PM)       1   101   美国   mm/dd/yyyy       ...

  3. 实现正在加载中界面的Android库:DynamicBox

    转载. DynamicBox是一个Android库,能够inflates自定义布局来指示出: 正在加载内容 显示一个异常 或者是一个自定义视图     项目主页:http://www.open-ope ...

  4. 【转】iOS使用NSMutableAttributedString实现富文本

    iOS使用NSMutableAttributedString实现富文本 在iOS开发中,常常会有一段文字显示不同的颜色和字体,或者给某几个文字加删除线或下划线的需求.之前在网上找了一些资料,有的是重绘 ...

  5. windows编程中 一些前缀区分 IDR和IDD

    IDC_:控件的ID命名前缀(Control) IDM_:菜单的ID命名前缀(Menu) IDD_:对话框的ID命名前缀(Dialog) IDR_:资源的ID命名前缀(Resource) IDS_:字 ...

  6. js创建对象的三种方法:文本标识法和构造器函数法和返回对象的函数

    文本标识法和定义变量差不多,像这样 var obj = {name:'HanMM','2':'Dali'}; 函数构造器法  先创建一个对象函数 function Obj() { this.addre ...

  7. HTML5拖放API

    拖放事件事件提供了拖放可以控制几乎所有方面的拖放操作.棘手的部分是确定每个事件触发:在拖项目火:别人火下降的目标.拖动项时,以下事件(按照这个顺序): 拖曳开始拖dragend此刻你把鼠标按钮和开始移 ...

  8. yii2源码学习笔记(六)

    Behvaior类,Behavior类是所有事件类的基类: 目录yii2\base\Behavior.php <?php /** * @link http://www.yiiframework. ...

  9. linux根目录下各文件的作用

    各文件详列:   /bin 存放常用命令的目录(二进制可执行命令)    /dev 设备特殊文件    /etc 存放配置相关的文件(系统管理和配置文件)    /etc/rc.d 启动的配置文件和脚 ...

  10. DEDECMS 关键字不能小于2个字节!

    今天在做DEDECMS模板时,突然遇到了“关键字不能小于2个字节!”晕,是怎么回事呢?百度了一下,找到了答案,把他记录下来,方便自己日后再遇到这种问题时,可以查询: <form name=&qu ...