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. C# 内存管理优化畅想(三)---- 其他方法&结语

    前两篇文章提出的优化方法,都是不需要修改源代码的,而是在CLR或JIT层面进行自动优化的.但本文中提出的优化方法则需要引入新的语法,开发者只有在源代码中使用了这些新语法,才会获得优化. 1. 允许对象 ...

  2. CSS样式权值

    内联样式表(InLine style)>内部样式表(Internal style sheet)>外部样式表(External style sheet) 例外:但如果外部样式表放在内部样式表 ...

  3. <html:text> Id属性

    可能 会遇到这样 的问题,需要通过document.getElementById得到<html:text>标签的id, 可是据说ie设置property后id就是一样的了,不过具体没有去测 ...

  4. .net又一个生成缩略图的方法,不变形,非常好用

    生成缩略图是一个十分常用功能,找到了一个方法,重写部分代码,实用又好用,.net又一个生成缩略图的方法,不变形 /// <summary> /// 为图片生成缩略图 by 何问起 /// ...

  5. 向RichTextBox控件不停的AppendText数据时,如何把光标的焦点始终显示到最后

    上面是csdn上的一个网友的问题,我的一个实现如下://让文本框获取焦点this.richTextBoxInfo.Focus();//设置光标的位置到文本尾this.richTextBoxInfo.S ...

  6. opencv安装及学习资料

    第一次装时win7+VS2010+opencv3.0,结果不成功,原因解压出来的没有vc10,可能新版本不在支持vc的旧版本了.所以换了VS2013+opencv3.0,比较经典的安装时VS2010+ ...

  7. 基于GBT28181:SIP协议组件开发-----------第三篇SIP注册流程分析实现

    原创文章,引用请保证原文完整性,尊重作者劳动,原文地址http://www.cnblogs.com/qq1269122125/p/3941172.html,qq:1269122125. 上两章节简要的 ...

  8. 复制JAVABEAN中的属性到另外一个JAVABEAN中

    下午写了一个属性复制方法,记录如下: class POUtil{ /** * * Function : 将一个source中的属性到复制到dest * @author : Liaokailin * C ...

  9. java逻辑运算符&&、&、||、|的详解

    public class OperatorDemo{ public static void main(String args[]) { //当我们执行一下代码时会报错(&属于没短路的) if( ...

  10. ThinkPHP框架下,给jq动态添加的标签添加点击事件移除标签

    jq移除标签主要就是$("#要移除的id").remove();不再赘述,这里要提醒的是jq中动态添加标签后怎样添加点击事件.一般的jq添加点击事件是用这种方法$("#i ...