A15203 | Mark the Photographer
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Mark is asked to take a group photo of $2n$ people. The $i$ -th person has height $h_i$ units.
To do so, he ordered these people into two rows, the front row and the back row, each consisting of $n$ people. However, to ensure that everyone is seen properly, the $j$ -th person of the back row must be at least $x$ units taller than the $j$ -th person of the front row for each $j$ between $1$ and $n$ , inclusive.
Help Mark determine if this is possible.
To do so, he ordered these people into two rows, the front row and the back row, each consisting of $n$ people. However, to ensure that everyone is seen properly, the $j$ -th person of the back row must be at least $x$ units taller than the $j$ -th person of the front row for each $j$ between $1$ and $n$ , inclusive.
Help Mark determine if this is possible.
输入格式
The first line contains one integer $t$ ( $1\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 $n$ and $x$ ( $1\leq n\leq 100$ , $1\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 $2n$ positive integers $h_1,h_2,\ldots,h_{2n}$ ( $1\leq h_i\leq 10^3$ ) — the height of each person in units.
Note that the sum of $n$ over all test cases is not bounded.
The first line of each test case contains two positive integers $n$ and $x$ ( $1\leq n\leq 100$ , $1\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 $2n$ positive integers $h_1,h_2,\ldots,h_{2n}$ ( $1\leq h_i\leq 10^3$ ) — the height of each person in units.
Note that the sum of $n$ over all test cases is not bounded.
输出格式
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).
You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answers).
输入输出样例
输入 #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 $9$ $12$ $16$ Front $3$ $1$ $10$ It works because
- $h_3-h_2 = 9-3 \geq 6$ ,
- $h_5-h_1 = 12-1\geq 6$ , and
- $h_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.
Back $9$ $12$ $16$ Front $3$ $1$ $10$ It works because
- $h_3-h_2 = 9-3 \geq 6$ ,
- $h_5-h_1 = 12-1\geq 6$ , and
- $h_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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted