C. Need More Arrays

time limit per test

2 seconds

memory limit per test

256 megabytes

Given an array a and n integers. It is sorted in non-decreasing order, that is, ai≤ai+1 for all 1≤i<n.

You can remove any number of elements from the array (including the option of not removing any at all) without changing the order of the remaining elements. After the removals, the following will occur:

  • a1 is written to a new array;
  • if a1+1<a2, then a2 is written to a new array; otherwise, a2 is written to the same array as a1;
  • if a2+1<a3, then a3 is written to a new array; otherwise, a3 is written to the same array as a2;

For example, if a=1,2,4,6, then:

  • a1=1 is written to the new array, resulting in arrays: 1;
  • a1+1=2, so a2=2 is added to the existing array, resulting in arrays: 1,2;
  • a2+1=3, so a3=4 is written to a new array, resulting in arrays: 1,2 and 4;
  • a3+1=5, so a4=6 is written to a new array, resulting in arrays: 1,2, 4, and 6.

Your task is to remove elements in such a way that the described algorithm creates as many arrays as possible. If you remove all elements from the array, no new arrays will be created.

Input

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

The first line of each test case contains one integer n (1≤n≤2⋅105) --- the length of the array.

The second line of each test case contains n integers a1,a2,...,an (1≤ai≤106, ai≤ai+1) --- the elements of the array.

It is guaranteed that the sum of n across all test cases does not exceed 2⋅105.

Output

For each test case, output one integer --- the maximum number of arrays that can be obtained by removing any (possibly zero) number of elements.

Example

Input

Copy

复制代码

6

6

1 2 3 4 5 6

3

1 2 3

4

1 2 2 4

1

2

3

1 4 8

2

1 1

Output

Copy

复制代码
3
2
2
1
3
1

Note

In the first example, you can remove a3 and a5, then a=1,2,4,6, the process of forming arrays for it is shown in the statement.

In the second example, you need to remove a2, after which a=1,3, and the arrays 1 and 3 will be written.

In the third example, no removals are needed; for a=1,2,2,4, the arrays 1,2,2 and 4 will be written.

解题说明:此题采用贪心算法,为了得到尽可能多的数组,那么只需要找出那些ai+1<ai+1的情况,从左到右遍历,不满足条件就删除这个元素。

cpp 复制代码
#include<stdio.h>

int arr[200008];

int main() 
{
	int t;
	scanf("%d", &t);
	while (t--)
	{
		int n;
		scanf("%d", &n);
		
		for (int i = 0; i < n; i++) 
		{
			scanf("%d", &arr[i]);
		}
		int count = 1;
		int ref = arr[0];
		for (int i = 0; i < n - 1; i++) 
		{
			if (ref + 1 < arr[i + 1]) 
			{
				count++;
				ref = arr[i + 1];
			}
		}
		printf("%d\n", count);
	}
	return 0;
}
相关推荐
春风解人意1 小时前
从零开始学习嵌入式P32----网络基础之TCP
c语言·网络·学习·tcp/ip
小灰灰搞电子1 小时前
Rust+Slint 实现动态消息提示框源码分享
开发语言·后端·rust
传奇开心果编程3 小时前
【Rust入门知识点学与练】第21课:Trait 进阶 Advanced Traits
开发语言·学习·rust
新时代牛马3 小时前
字符设备驱动完整篇:从 cdev_add、file_operations 到chrdev_open 与排障
开发语言·python
swordbob3 小时前
ReentrantLock 与 AQS 完整学习手册
java·开发语言
是隼人4 小时前
buuctf-pwn inndy_echo(32位fmt)题解(学习过程持续更新)
c语言·学习·安全·pwn入门·ctf入门
白山编程大哥4 小时前
Java OutputStreamWriter 详解:从字符到字节的桥梁
java·开发语言·python
shmily麻瓜小菜鸡5 小时前
JavaScript / TypeScript 易踩坑知识点 —— 异步编程类
开发语言·javascript·typescript
刃神太酷啦5 小时前
Redis 进阶核心:持久化 (RDB/AOF)、事务与主从复制全解析----《Hello Redis!》(5)
linux·c语言·数据库·c++·redis·缓存·bootstrap
七夜zippoe5 小时前
为什么 2026 年每个 Java 团队都该懂 AI Agent
java·开发语言·人工智能