CF1399A.Remove Smallest

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given the array aa consisting of nn positive (greater than zero) integers.

In one move, you can choose two indices ii and jj (i≠ji \ne j) such that the absolute difference between aia_i and aja_j is no more than one (∣ai−aj∣≤1|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 tt independent test cases.

给你一个由 nn 个正整数(均大于零)组成的数组 aa。

在一次操作中,你可以选择两个下标 ii 和 jj(i≠ji \ne j),满足 aia_i 与 aja_j 的绝对差值不超过 11(即 ∣ai−aj∣≤1|a_i - a_j| \le 1),然后移除这两个元素中较小的那个。若两元素相等,则可任选其一移除(但必须恰好移除一个)。

你的任务是判断:能否通过若干次(可能为零次)这样的操作,最终使数组仅剩一个元素。

你需要回答 tt 个相互独立的测试用例。

输入格式

The first line of the input contains one integer tt (1≤t≤10001 \le t \le 1000) — the number of test cases. Then tt test cases follow.

The first line of the test case contains one integer nn (1≤n≤501 \le n \le 50) — the length of aa. The second line of the test case contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1001 \le a_i \le 100), where aia_i is the ii-th element of aa.

输入的第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000),表示测试用例的数量。随后是 tt 个测试用例。

每个测试用例的第一行包含一个整数 nn(1≤n≤501 \le n \le 50),表示数组 aa 的长度。每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1001 \le a_i \le 100),其中 aia_i 是数组 aa 的第 ii 个元素。

输出格式

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.

对于每个测试用例,输出答案:如果可以通过执行若干次(可能为零次)题目描述中的操作得到仅包含一个元素的数组,则输出 "YES";否则输出 "NO"。

输入输出样例

  • 输入#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=1i=1 and j=3j=3 and remove aia_i (so aa becomes [2;2][2; 2]);
  • choose i=1i=1 and j=2j=2 and remove aja_j (so aa becomes [2][2]).

In the second test case of the example, we can choose any possible ii and jj 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 22 and 44.

在示例的第一个测试用例中,我们可以执行以下操作序列:

  • 选择 i=1i=1 和 j=3j=3,并移除 aia_i(此时 aa 变为 [2;2][2; 2]);
  • 选择 i=1i=1 和 j=2j=2,并移除 aja_j(此时 aa 变为 [2][2])。

在示例的第二个测试用例中,每次操作均可任选 ii 和 jj,且移除哪个元素均无影响。

在示例的第三个测试用例中,无法同时消除 22 和 44。

输入解题思路,AI测评打分。不知道怎么写?

首页