CF1903A.Halloumi Boxes

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Theofanis is busy after his last contest, as now, he has to deliver many halloumis all over the world. He stored them inside nn boxes and each of which has some number aia_i written on it.

He wants to sort them in non-decreasing order based on their number, however, his machine works in a strange way. It can only reverse any subarray†^{\dagger} of boxes with length at most kk.

Find if it's possible to sort the boxes using any number of reverses.

†^{\dagger} Reversing a subarray means choosing two indices ii and jj (where 1≤i≤j≤n1 \le i \le j \le n) and changing the array a1,a2,…,ana_1, a_2, \ldots, a_n to a1,a2,…,ai−1,  aj,aj−1,…,ai,  aj+1,…,an−1,ana_1, a_2, \ldots, a_{i-1}, \; a_j, a_{j-1}, \ldots, a_i, \; a_{j+1}, \ldots, a_{n-1}, a_n. The length of the subarray is then j−i+1j - i + 1.

Theofanis 在他上一场 比赛 后非常忙碌,因为他现在需要将大量 halloumi 送往世界各地。他把这些 halloumi 存放在 nn 个盒子中,每个盒子上写有一个数字 aia_i。

他希望根据这些数字将盒子按非递减顺序排序。然而,他的机器工作方式十分奇特:它只能翻转长度至多为 kk 的任意子数组†^{\dagger}。

请判断:是否可以通过若干次翻转操作,将盒子排序成功?

†^{\dagger} 翻转一个子数组,是指选择两个下标 ii 和 jj(满足 1≤i≤j≤n1 \le i \le j \le n),并将原数组 a1,a2,…,ana_1, a_2, \ldots, a_n 变为

a1,a2,…,ai−1,  aj,aj−1,…,ai,  aj+1,…,an−1,an.a_1, a_2, \ldots, a_{i-1},\; a_j, a_{j-1}, \ldots, a_i,\; a_{j+1}, \ldots, a_{n-1}, a_n.

该子数组的长度为 j−i+1j - i + 1。

输入格式

The first line contains a single integer tt (1≤t≤1001 \le t \le 100) — the number of test cases.

Each test case consists of two lines.

The first line of each test case contains two integers nn and kk (1≤k≤n≤1001 \le k \le n \le 100) — the number of boxes and the length of the maximum reverse that Theofanis can make.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \le a_i \le 10^{9}) — the number written on each box.

第一行包含一个整数 tt(1≤t≤1001 \le t \le 100)—— 测试用例的数量。

每个测试用例由两行组成。

每个测试用例的第一行包含两个整数 nn 和 kk(1≤k≤n≤1001 \le k \le n \le 100)—— 箱子的数量,以及 Theofanis 能执行的最长反转操作的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \le a_i \le 10^{9})—— 每个箱子上所写的数字。

输出格式

For each test case, print YES (case-insensitive), if the array can be sorted in non-decreasing order, or NO (case-insensitive) otherwise.

对于每个测试用例,如果该数组可以被排序为非递减顺序,则输出 YES(不区分大小写);否则输出 NO(不区分大小写)。

输入输出样例

  • 输入#1

    5
    3 2
    1 2 3
    3 1
    9 9 9
    4 4
    6 4 2 1
    4 3
    10 3 830 14
    2 1
    3 1

    输出#1

    YES
    YES
    YES
    YES
    NO

说明/提示

In the first two test cases, the boxes are already sorted in non-decreasing order.

In the third test case, we can reverse the whole array.

In the fourth test case, we can reverse the first two boxes and the last two boxes.

In the fifth test case, it can be shown that it's impossible to sort the boxes.

在前两个测试用例中,盒子已经按非递减顺序排好。

在第三个测试用例中,我们可以将整个数组反转。

在第四个测试用例中,我们可以反转前两个盒子以及后两个盒子。

在第五个测试用例中,可以证明无法将盒子排序。

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

首页