欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1903A.Halloumi Boxes
Halloumi Boxes
Theofanis is busy after his last contest, as now, he has to deliver many halloumis all over the world. He stored them inside boxes and each of which has some number 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 of boxes with length at most .
Find if it's possible to sort the boxes using any number of reverses.
Reversing a subarray means choosing two indices and (where ) and changing the array to $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$. The length of the subarray is then .
Input
The first line contains a single integer () — the number of test cases.
Each test case consists of two lines.
The first line of each test case contains two integers and () — the number of boxes and the length of the maximum reverse that Theofanis can make.
The second line contains integers () — the number written on each box.
Output
For each test case, print YES (case-insensitive), if the array can be sorted in non-decreasing order, or NO (case-insensitive) otherwise.
Note
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.
Samples
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
YES
YES
YES
YES
NO
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |