A. Closest Point
time limit per test
2 seconds
memory limit per test
512 megabytes
Consider a set of points on a line. The distance between two points ii and jj is |i−j||i−j|.
The point ii from the set is the closest to the point jj from the set, if there is no other point kk in the set such that the distance from jj to kk is strictly less than the distance from jj to ii. In other words, all other points from the set have distance to jj greater or equal to |i−j||i−j|.
For example, consider a set of points {1,3,5,8}{1,3,5,8}:
- for the point 11, the closest point is 33 (other points have distance greater than |1−3|=2|1−3|=2);
- for the point 33, there are two closest points: 11 and 55;
- for the point 55, the closest point is 33 (but not 88, since its distance is greater than |3−5||3−5|);
- for the point 88, the closest point is 55.
You are given a set of points. You have to add an integer point into this set in such a way that it is different from every existing point in the set, and it becomes the closest point to every point in the set. Is it possible?
Input
The first line contains one integer tt (1≤t≤10001≤t≤1000) — the number of test cases.
Each test case consists of two lines:
- the first line contains one integer nn (2≤n≤402≤n≤40) — the number of points in the set;
- the second line contains nn integers x1,x2,…,xnx1,x2,…,xn (1≤x1<x2<⋯<xn≤1001≤x1<x2<⋯<xn≤100) — the points from the set.
Output
For each test case, print YES if it is possible to add a new point according to the conditions from the statement. Otherwise, print NO.
Example
Input
Copy
3
2
3 8
2
5 6
6
1 2 3 4 5 10
Output
Copy
YES NO NO
Note
In the first example, the point 77 will be the closest to both 33 and 88.
In the second example, it is impossible to add an integer point so that it becomes the closest to both 55 and 66, and is different from both of them.
解题说明:水题,只让插入一个数字而且要满足要求,肯定只能在2个数字中插入一个数字,其他不符合条件。两个数字中插入一个需要至少相减大于1.
#include<stdio.h>
#include<math.h>
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
int n;
scanf("%d", &n);
int a[n];
for (int i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
if (n == 2 && abs(a[0] - a[1]) != 1)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
return 0;
}