A13739 | Remove Smallest
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given the array $a$ consisting of $n$ positive (greater than zero) integers.
In one move, you can choose two indices $i$ and $j$ ( $i \ne j$ ) such that the absolute difference between $a_i$ and $a_j$ is no more than one ( $|a_i - a_j| \le 1$ ) and remove the smallest of these two elements. If two elements are equal, you can remove any of them (but exactly one).
Your task is to find if it is possible to obtain the array consisting of only one element using several (possibly, zero) such moves or not.
You have to answer $t$ independent test cases.
In one move, you can choose two indices $i$ and $j$ ( $i \ne j$ ) such that the absolute difference between $a_i$ and $a_j$ is no more than one ( $|a_i - a_j| \le 1$ ) and remove the smallest of these two elements. If two elements are equal, you can remove any of them (but exactly one).
Your task is to find if it is possible to obtain the array consisting of only one element using several (possibly, zero) such moves or not.
You have to answer $t$ independent test cases.
输入格式
The first line of the input contains one integer $t$ ( $1 \le t \le 1000$ ) — the number of test cases. Then $t$ test cases follow.
The first line of the test case contains one integer $n$ ( $1 \le n \le 50$ ) — the length of $a$ . The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 100$ ), where $a_i$ is the $i$ -th element of $a$ .
The first line of the test case contains one integer $n$ ( $1 \le n \le 50$ ) — the length of $a$ . The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 100$ ), where $a_i$ is the $i$ -th element of $a$ .
输出格式
For each test case, print the answer: "YES" if it is possible to obtain the array consisting of only one element using several (possibly, zero) moves described in the problem statement, or "NO" otherwise.
输入输出样例
输入 #1
5 3 1 2 2 4 5 5 5 5 3 1 2 4 4 1 3 4 4 1 100
输出 #1
YES YES NO NO YES
In the first test case of the example, we can perform the following sequence of moves:
- choose $i=1$ and $j=3$ and remove $a_i$ (so $a$ becomes $[2; 2]$ );
- choose $i=1$ and $j=2$ and remove $a_j$ (so $a$ becomes $[2]$ ).
In the second test case of the example, we can choose any possible $i$ and $j$ any move and it doesn't matter which element we remove.
In the third test case of the example, there is no way to get rid of $2$ and $4$ .
- choose $i=1$ and $j=3$ and remove $a_i$ (so $a$ becomes $[2; 2]$ );
- choose $i=1$ and $j=2$ and remove $a_j$ (so $a$ becomes $[2]$ ).
In the second test case of the example, we can choose any possible $i$ and $j$ any move and it doesn't matter which element we remove.
In the third test case of the example, there is no way to get rid of $2$ and $4$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted