CF1705A.Mark the Photographer

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Mark is asked to take a group photo of 2n2n people. The ii-th person has height hih_i units.

To do so, he ordered these people into two rows, the front row and the back row, each consisting of nn people. However, to ensure that everyone is seen properly, the jj-th person of the back row must be at least xx units taller than the jj-th person of the front row for each jj between 11 and nn, inclusive.

Help Mark determine if this is possible.

马克被要求为 2n2n 个人拍摄一张集体照。第 ii 个人的身高为 hih_i 个单位。

为此,他将这些人排成两行:前排和后排,每行各有 nn 人。然而,为了确保每个人都能被清晰地看到,对于每个 jj(1≤j≤n1 \leq j \leq n),后排第 jj 个人的身高必须至少比前排第 jj 个人高 xx 个单位。

请帮助马克判断这是否可行。

输入格式

The first line contains one integer tt (1≤t≤1001\leq t\leq 100) — the number of test cases. Each test case consists of two lines.

The first line of each test case contains two positive integers nn and xx (1≤n≤1001\leq n\leq 100, 1≤x≤1031\leq x\leq 10^3) — the number of people in each row and the minimum difference Mark wants.

The second line of each test case contains 2n2n positive integers h1,h2,…,h2nh_1,h_2,\ldots,h_{2n} (1≤hi≤1031\leq h_i\leq 10^3) — the height of each person in units.

Note that the sum of nn over all test cases is not bounded.

第一行包含一个整数 tt(1≤t≤1001\leq t\leq 100),表示测试用例的数量。每个测试用例由两行组成。

每个测试用例的第一行包含两个正整数 nn 和 xx(1≤n≤1001\leq n\leq 100,1≤x≤1031\leq x\leq 10^3),分别表示每排的人数以及 Mark 所要求的最小身高差。

每个测试用例的第二行包含 2n2n 个正整数 h1,h2,…,h2nh_1,h_2,\ldots,h_{2n}(1≤hi≤1031\leq h_i\leq 10^3),表示每个人的身高(单位)。

注意:所有测试用例中 nn 的总和没有上界。

输出格式

For each test case, print a single line containing "YES" if Mark could arrange people satisfying his condition and "NO" otherwise.

You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answers).

对于每个测试用例,如果 Mark 能够按照他的条件安排人员,则输出一行 “YES”;否则输出 “NO”。

你可以以任意大小写形式输出每个字母(例如,YES、Yes、yes、yEs 均会被识别为肯定回答)。

输入输出样例

  • 输入#1

    3
    3 6
    1 3 9 10 12 16
    3 1
    2 5 2 2 2 5
    1 2
    8 6

    输出#1

    YES
    NO
    YES

说明/提示

In the first test case, one possible order is to have the third, fifth, and sixth person on the back row and the second, first, and fourth on the front row. The heights of the people will look like this.

Back

99

1212

1616

Front

33

11

1010

It works because

  • h3−h2=9−3≥6h_3-h_2 = 9-3 \geq 6,
  • h5−h1=12−1≥6h_5-h_1 = 12-1\geq 6, and
  • h6−h4=16−10≥6h_6-h_4 = 16-10\geq 6.

In the second test case, it can be shown there is no way to order people in a way that satisfies the condition.

In the third test case, the only way to arrange people to satisfy the condition is to have the first person on the back row and the second person on the front row.

在第一个测试用例中,一种可能的排列方式是:将第三人、第五人和第六人安排在后排,第二人、第一人和第四人安排在前排。此时各人的身高如下所示:

后排

99

1212

1616

前排

33

11

1010

该排列满足条件,因为

  • h3−h2=9−3≥6h_3-h_2 = 9-3 \geq 6,
  • h5−h1=12−1≥6h_5-h_1 = 12-1\geq 6,且
  • h6−h4=16−10≥6h_6-h_4 = 16-10\geq 6。

在第二个测试用例中,可以证明不存在满足该条件的人员排列方式。

在第三个测试用例中,唯一满足条件的人员排列方式是:将第一人安排在后排,第二人安排在前排。

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

首页