博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Educational Codeforces Round 85 (Rated for Div. 2)A. Level Statistics(题解)
阅读量:4034 次
发布时间:2019-05-24

本文共 3795 字,大约阅读时间需要 12 分钟。

Polycarp has recently created a new level in this cool new game Berlio Maker 85 and uploaded it online. Now players from all over the world can try his level.

All levels in this game have two stats to them: the number of plays and the number of clears. So when a player attempts the level, the number of plays increases by 1. If he manages to finish the level successfully then the number of clears increases by 1 as well. Note that both of the statistics update at the same time (so if the player finishes the level successfully then the number of plays will increase at the same time as the number of clears).

Polycarp is very excited about his level, so he keeps peeking at the stats to know how hard his level turns out to be.

So he peeked at the stats n times and wrote down n pairs of integers — (p1,c1),(p2,c2),…,(pn,cn), where pi is the number of plays at the i-th moment of time and ci is the number of clears at the same moment of time. The stats are given in chronological order (i.e. the order of given pairs is exactly the same as Polycarp has written down).

Between two consecutive moments of time Polycarp peeked at the stats many players (but possibly zero) could attempt the level.

Finally, Polycarp wonders if he hasn’t messed up any records and all the pairs are correct. If there could exist such a sequence of plays (and clears, respectively) that the stats were exactly as Polycarp has written down, then he considers his records correct.

Help him to check the correctness of his records.

For your convenience you have to answer multiple independent test cases.

Input

The first line contains a single integer T (1≤T≤500) — the number of test cases.

The first line of each test case contains a single integer n (1≤n≤100) — the number of moments of time Polycarp peeked at the stats.

Each of the next n lines contains two integers pi and ci (0≤pi,ci≤1000) — the number of plays and the number of clears of the level at the i-th moment of time.

Note that the stats are given in chronological order.

Output

For each test case print a single line.

If there could exist such a sequence of plays (and clears, respectively) that the stats were exactly as Polycarp has written down, then print “YES”.

Otherwise, print “NO”.

You can print each letter in any case (upper or lower).

Example

input
6
3
0 0
1 1
1 2
2
1 0
1000 3
4
10 1
15 2
10 2
15 2
1
765 432
2
4 4
4 3
5
0 0
1 0
1 0
1 0
1 0
output
NO
YES
NO
YES
NO
YES

Note

In the first test case at the third moment of time the number of clears increased but the number of plays did not, that couldn’t have happened.

The second test case is a nice example of a Super Expert level.

In the third test case the number of plays decreased, which is impossible.

The fourth test case is probably an auto level with a single jump over the spike.

In the fifth test case the number of clears decreased, which is also impossible.

Nobody wanted to play the sixth test case; Polycarp’s mom attempted it to make him feel better, however, she couldn’t clear it.

题目比较简单,满足的条件:

  • 非递减
  • pi>=ci
  • pi-p(i-1)>= ci-c(i-1)

具体实现:

#include
#include
using namespace std;int p[105], c[105];int main() {
int t; cin >> t; while (t--) {
int n; cin>>n; for (int i = 1; i <= n; i++) {
cin>>p[i]; cin>>c[i]; } int flag = 1; p[0] = 0; c[0] = 0; for (int i = 1; i <= n; i++) {
if (p[i] == p[i - 1]) {
if (c[i] == c[i - 1]) continue; else flag = 0; } if (p[i] > p[i - 1]) {
if (c[i] == c[i - 1]) continue; else if (c[i] > c[i - 1]) {
if (c[i] - c[i - 1] <= p[i] - p[i - 1]) continue; else flag = 0; } else flag = 0; } if (p[i] < p[i - 1]) flag = 0; } if (!flag) printf("NO\n"); else printf("YES\n"); } return 0;}

码字不易,留个赞吧~

转载地址:http://hafdi.baihongyu.com/

你可能感兴趣的文章
使用maven-war-plugin 对Maven项目进行动态打包
查看>>
spring定时任务配置
查看>>
Log4j2 配置笔记(Eclipse+maven+SpringMVC)
查看>>
java设计模式之简单工厂模式
查看>>
struts2中constant参数设置
查看>>
Struts2中struts.multipart.maxSize设置
查看>>
CheckStyle插件在eclipse中的安装及配置
查看>>
PowerDesigner 导入数据库建表SQL脚本生成物理模型
查看>>
idea的xml配置中url显示:URI is not registered ( Setting | Project Settings | Schemas and DTDs )
查看>>
如何修改源码>重新打包>替换源文件
查看>>
@Slf4j注解的使用
查看>>
SpringBoot通过配置devtools实现热部署
查看>>
springboot+springsecurity+jwt进行系统权限开发
查看>>
使用轻量级工具emoji-java处理emoji表情字符
查看>>
排序算法的C语言实现C代码
查看>>
c语言快排函数调用方法模板
查看>>
c语言实现多行输入输出数据
查看>>
查找算法
查看>>
C语言单链表实现
查看>>
SQL基本命令集合整理
查看>>