## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

# [Solution] Wonderful Permutation Codeforces Solution

A. Wonderful Permutation
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a permutation

${p}_{1},{p}_{2},\dots ,{p}_{n}$ of length $n$ and a positive integer $k\le n$.

In one operation you can choose two indices $i$ and $j$ ($1\le i) and swap ${p}_{i}$ with ${p}_{j}$.

Find the minimum number of operations needed to make the sum ${p}_{1}+{p}_{2}+\dots +{p}_{k}$ as small as possible.

A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $\left[2,3,1,5,4\right]$ is a permutation, but $\left[1,2,2\right]$ is not a permutation ($2$ appears twice in the array) and $\left[1,3,4\right]$ is also not a permutation ($n=3$ but there is $4$ in the array).

Input

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1\le t\le 100$).

Solution Click Below:-  👉
👇👇👇👇👇

Description of the test cases follows.

The first line of each test case contains two integers $n$ and $k$ ($1\le k\le n\le 100$).

The second line of each test case contains $n$ integers ${p}_{1},{p}_{2},\dots ,{p}_{n}$ ($1\le {p}_{i}\le n$). It is guaranteed that the given numbers form a permutation of length $n$.

Output

For each test case print one integer — the minimum number of operations needed to make the sum ${p}_{1}+{p}_{2}+\dots +{p}_{k}$ as small as possible.