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<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long LL; LL a[];
int main()
{
LL n,i,x,y;
while(scanf("%lld",&n)>)
{
LL max1=-;
for(i=;i<=n;i++)
{
scanf("%lld%lld",&x,&y);
a[i]=x-y;
}
sort(a+,a++n);
max1=a[n];
LL sum=;
LL hxl=a[n];
for(i=;i<=n-;i++)
{
sum=sum+a[i];
hxl=(hxl+a[i])%;
}
if(max1>sum || hxl==) printf("NO\n");
else printf("YES\n");
}
return ;
}

zoj Gao The Sequence的更多相关文章

  1. zoj 3672 Gao The Sequence

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4915题意:a[k]-一个任意的数,这个数要等于a[1]~a[k]每个数减去任意 ...

  2. zoj3672 Gao The Sequence

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

  3. ZOJ 4060 - Flippy Sequence - [思维题][2018 ACM-ICPC Asia Qingdao Regional Problem C]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4060 题意: 给出两个 $0,1$ 字符串 $S,T$,现在你有 ...

  4. ZOJ Monthly, November 2012

    A.ZOJ 3666 Alice and Bob 组合博弈,SG函数应用 #include<vector> #include<cstdio> #include<cstri ...

  5. ZOJ Monthly, March 2018 题解

    [题目链接] A. ZOJ 4004 - Easy Number Game 首先肯定是选择值最小的 $2*m$ 进行操作,这些数在操作的时候每次取一个最大的和最小的相乘是最优的. #include & ...

  6. 矩阵连乘积 ZOJ 1276 Optimal Array Multiplication Sequence

    题目传送门 /* 题意:加上适当的括号,改变计算顺序使得总的计算次数最少 矩阵连乘积问题,DP解决:状态转移方程: dp[i][j] = min (dp[i][k] + dp[k+1][j] + p[ ...

  7. ZOJ - 4104 Sequence in the Pocket(思维+元素移至列首排序)

    Sequence in the Pocket Time Limit: 1 Second      Memory Limit: 65536 KB DreamGrid has just found an ...

  8. ZOJ 3408 Gao

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

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

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

随机推荐

  1. SQL isnull函数

    select * from emp;

  2. codeforces 70D Professor's task(动态二维凸包)

    题目链接:http://codeforces.com/contest/70/problem/D Once a walrus professor Plato asked his programming ...

  3. MVC Controller弹窗的几种方式

    MVC3 Controller弹窗的几种方式   return Content("<script language='javascript' type='text/javascript ...

  4. java mybatis XML文件中大于号小于号转义

    因为这个是xml文件不允许出现类似“>”这样的字符 用了转义字符把>和<替换掉,然后就没有问题了. <=   相当于 <= >=  相当于 >= XML转义字 ...

  5. 转一篇 adaboost 的好文 AdaBoost简介及训练误差分析

    AdaBoost简介及训练误差分析 http://wenku.baidu.com/link?url=y9Q2qjrJr6IShyY5EQEmvkPZmmP4t3HOdHUgMWaIffI9W0uzTr ...

  6. ubuntu sublime-text package control

    1.ubuntu 环境下sublime-text的 package control一直配置失败 因为我下的是sublime-text3,而网上一般都是sublime-text2的教程. 2.subli ...

  7. HGE引擎之hgeSprite

    一.hgeSprite类 hgeSprite是一个精灵实体的HGE帮助类. 1.构造函数 创建和初始化一个hgeSprite对象. hgeSprite(HTEXTURE tex, float x, f ...

  8. android 学习随笔二(读写文件)

    在android读写文件 RAM:运行内存,相当于电脑的内存 ROM:内部存储空间,相当电脑硬盘,android手机必须有的 SD卡:外部存储空间,相当电脑的移动硬盘,不是必须的.手机如果内置16G存 ...

  9. 苹果系统直接读写 ntfs 磁盘

    苹果系统对 ntfs 能读,但不能写. 方案1:修改 fstab 法 ======================================== 读写支持.在使用本教学文章之前,请先确定你没有安 ...

  10. Linux kernel的 Makefile和Kconfig以及Make menuconfig的关系【转】

    本文转载自:http://blog.sina.com.cn/s/blog_4ba5b45e0102e6vp.html 熟悉内核的Makefile对开发设备驱动.理解内核代码结构都是非常重要的linux ...