A. Rudolph and Cut the Rope

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

There are n� nails driven into the wall, the i�-th nail is driven ai�� meters above the ground, one end of the bi�� meters long rope is tied to it. All nails hang at different heights one above the other. One candy is tied to all ropes at once. Candy is tied to end of a rope that is not tied to a nail.

To take the candy, you need to lower it to the ground. To do this, Rudolph can cut some ropes, one at a time. Help Rudolph find the minimum number of ropes that must be cut to get the candy.

The figure shows an example of the first test:

Input

The first line contains one integer t� (1≤t≤1041≤�≤104) --- the number of test cases.

The first line of each test case contains one integer n� (1≤n≤501≤�≤50) --- the number of nails.

The i�-th of the next n� lines contains two integers ai�� and bi�� (1≤ai,bi≤2001≤��,��≤200) --- the height of the i�-th nail and the length of the rope tied to it, all ai�� are different.

It is guaranteed that the data is not contradictory, it is possible to build a configuration described in the statement.

Output

For each test case print one integer --- the minimum number of ropes that need to be cut to make the candy fall to the ground.

Example

input

Copy

复制代码

4

3

4 3

3 1

1 2

4

9 2

5 2

7 7

3 4

5

11 7

5 10

12 9

3 2

1 5

3

5 6

4 5

7 7

output

Copy

复制代码
2
2
3
0

解题说明:水题,此题分析一下就能发现,只要绳子长度小于高度,那就必须要切断才能让糖果落地,直接判断即可。

cpp 复制代码
#include<stdio.h>
int main()
{
	int m, n, a, b, ans;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		ans = 0;
		scanf("%d", &m);
		for (int j = 0; j < m; j++)
		{
			scanf("%d %d", &a, &b);
			if (a > b)
			{
				ans++;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}
相关推荐
是有头发的程序猿16 分钟前
用Open Claw接口做1688选品、价格监控、货源对比
开发语言·c++·人工智能
逆境不可逃34 分钟前
LeetCode 热题 100 之 543. 二叉树的直径 102. 二叉树的层序遍历 108. 将有序数组转换为二叉搜索树 98. 验证二叉搜索树
算法·leetcode·职场和发展
计算机安禾36 分钟前
【数据结构与算法】第19篇:树与二叉树的基础概念
c语言·开发语言·数据结构·c++·算法·visual studio code·visual studio
副露のmagic1 小时前
哈希章节 leetcode 思路&实现
算法·leetcode·哈希算法
csuzhucong1 小时前
puzzle(1037)黑白、黑白棋局
算法
XiYang-DING1 小时前
【LeetCode】链表 + 快慢指针找中间 | 2095. 删除链表的中间节点
算法·leetcode·链表
Zarek枫煜1 小时前
[特殊字符] C3语言:传承C之高效,突破C之局限
c语言·开发语言·c++·单片机·嵌入式硬件·物联网·算法
寻寻觅觅☆1 小时前
东华OJ-基础题-30-求最晚和最早日期(C++)
数据结构·c++·算法
羊小蜜.2 小时前
Mysql 03: 连接查询全解——内连接、外连接与复合条件查询
数据库·mysql·算法·连接查询
_Twink1e2 小时前
[算法竞赛]九、C++标准模板库STL常用容器大全
开发语言·c++