ZOJ 3672 Gao The Sequence

来源:互联网 发布:centos 6 docker 1.12 编辑:程序博客网 时间:2024/05/02 06:09

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3672


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

33 24 25 232 07 13 1

Sample Output

YESNO

Author: LI, Wenchao
Contest: ZOJ Monthly, November 2012
Submit    Status


一道简单题。

#include<iostream>#include<cstring>#include<cstdio>#include<vector>#include<string>#include<sstream>#include<algorithm>#include<cmath>#include<vector>#include<set>#include<cstdlib>#include<map>using namespace std;#define CLR(A) memset(A,0,sizeof(A))int main(){    int n;    while(~scanf("%d",&n)){        long long sum=0,a,b;        long long maxv=0;        while(n--){            scanf("%lld%lld",&a,&b);            sum+=(a-b);            maxv=max(maxv,a-b);        }        if(sum&1||2*maxv>sum){            cout<<"NO"<<endl;        }        else{            cout<<"YES"<<endl;        }    }    return 0;}







0 0
原创粉丝点击