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. cookie和session区别

    cookie和session区 session是在服务器端保存用户信息,cookie是在客户端保存用户信息 session保存的是对象,cookie保存的是字符串 session会随回话结束而关闭,c ...

  2. HDU 3681 Prison Break(BFS+二分+状态压缩DP)

    Problem Description Rompire is a robot kingdom and a lot of robots live there peacefully. But one da ...

  3. the serializable class XXX does not declare a static final seriaVersionUID...的问题

    关于myeclips提示The serializable class XXX does not declare a static final serialVersionUID field of typ ...

  4. Thread create 创建进程

    #include "windows.h" #include "iostream" #include "stdio.h" void Start ...

  5. java多线程实现卖票小程序

    package shb.java.demo; /** * 多线程测试卖票小程序. * @Package:shb.java.demo * @Description: * @author shaobn * ...

  6. 03---Net基础加强

    多态---虚方法    (子类可以选择重写或者不重写) class Program { static void Main(string[] args) { Chinese cn1 = new Chin ...

  7. weka 文本分类(1)

    一.初始化设置 1 jvm out of memory 解决方案: 在weka SimpleCLI窗口依次输入java -Xmx 1024m 2 修改配置文件,使其支持中文: 配置文件是在Weka安装 ...

  8. C语言初学者代码中的常见错误与瑕疵(13)

    https://www.cpfn.org/bbs/viewtopic.php?f=85&t=5940&sid=ccbcf716d21191452e7c08a97b502337& ...

  9. 一个fork()系统调用的问题

    转载:http://coolshell.cn/articles/7965.html 题目:请问下面的程序一共输出多少个“-”? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ...

  10. 机器学习实战5:k-means聚类:二分k均值聚类+地理位置聚簇实例

    k-均值聚类是非监督学习的一种,输入必须指定聚簇中心个数k.k均值是基于相似度的聚类,为没有标签的一簇实例分为一类. 一 经典的k-均值聚类 思路: 1 随机创建k个质心(k必须指定,二维的很容易确定 ...