欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1566D1.Seating Arrangements (easy version)
Seating Arrangements (easy version)
It is the easy version of the problem. The only difference is that in this version .
In the cinema seats can be represented as the table with rows and columns. The rows are numbered with integers from to . The seats in each row are numbered with consecutive integers from left to right: in the -th row from to for all rows .
The table with seats indices
There are people who want to go to the cinema to watch a new film. They are numbered with integers from to . You should give exactly one seat to each person.
It is known, that in this cinema as lower seat index you have as better you can see everything happening on the screen. -th person has the level of sight . Let's define as the seat index, that will be given to -th person. You want to give better places for people with lower sight levels, so for any two people , such that it should be satisfied that .
After you will give seats to all people they will start coming to their seats. In the order from to , each person will enter the hall and sit in their seat. To get to their place, the person will go to their seat's row and start moving from the first seat in this row to theirs from left to right. While moving some places will be free, some will be occupied with people already seated. The inconvenience of the person is equal to the number of occupied seats he or she will go through.
Let's consider an example: , the person has the seat in the first row, the seats , , in the first row are already occupied, the seats and are free. The inconvenience of this person will be , because he will go through occupied seats and .
Find the minimal total inconvenience (the sum of inconveniences of all people), that is possible to have by giving places for all people (all conditions should be satisfied).
Input
The input consists of multiple test cases. The first line contains a single integer () — the number of test cases. Description of the test cases follows.
The first line of each test case contains two integers and (, ) — the number of rows and places in each row respectively.
The second line of each test case contains integers (), where is the sight level of -th person.
It's guaranteed that the sum of over all test cases does not exceed .
Output
For each test case print a single integer — the minimal total inconvenience that can be achieved.
Note
In the first test case, there is a single way to arrange people, because all sight levels are distinct. The first person will sit on the first seat, the second person will sit on the second place, the third person will sit on the third place. So inconvenience of the first person will be , inconvenience of the second person will be and inconvenience of the third person will be . The total inconvenience is .
In the second test case, people should sit as follows: , , , , . The total inconvenience will be .
Samples
4
1 3
1 2 3
1 5
2 1 5 3 3
1 2
2 1
1 6
2 3 2 1 1 1
3
6
0
1
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |