in problem D if https://codeforces.me/contest/2121/problem/D
N=50
array A is 50 49 48 47 46 .................1
array B is 100 99 98 97.......................
so we need 50*49*2 operation which is greater than 4900>1709
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3676 |
| 2 | Kevin114514 | 3659 |
| 3 | jiangly | 3640 |
| 4 | turmax | 3450 |
| 5 | tourist | 3382 |
| 6 | strapple | 3360 |
| 7 | Um_nik | 3354 |
| 8 | squareOf105 | 3348 |
| 9 | maroonrk | 3312 |
| 10 | idontwannadothis…e | 3191 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 155 |
| 2 | nik_exists | 151 |
| 3 | maspy | 149 |
| 4 | AmShZ | 145 |
| 5 | Um_nik | 143 |
| 6 | Errichto | 139 |
| 7 | BledDest | 136 |
| 8 | adamant | 134 |
| 9 | maroonrk | 132 |
| 10 | cry | 130 |
in problem D if https://codeforces.me/contest/2121/problem/D
N=50
array A is 50 49 48 47 46 .................1
array B is 100 99 98 97.......................
so we need 50*49*2 operation which is greater than 4900>1709
| Name |
|---|



but $$$n\leq 40$$$ according to the constraints of the problem
Read the editorial, Imma CP paste it for ya.
Using bubble sort, we will sort array $$$a$$$: while there exists an index $$$1 \leq i \lt n$$$ such that $$$a_i \gt a_{i+1}$$$, we will swap them. Similarly, we will sort array $$$b$$$.
In this part of the task, we will perform no more than
operations, since the number of swaps in bubble sort is equal to the number of inversions in the array.
Next, for all $$$1 \leq i \leq n$$$ such that $$$a_i \gt b_i$$$, we will swap $$$a_i$$$ and $$$b_i$$$. After this, we will satisfy both conditions and perform a total of no more than
operations.
The solution can be implemented in $$$O(n^2)$$$ time.
Code from the editorial:
Hope this helps, Editorial Link : https://codeforces.me/blog/entry/143822