A. Wonderful Permutation
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output
Problem Statement
You are given a permutation p 1 , p 2 , … , p n p_1,p_2,…,p_n p1,p2,…,pn of length n and a positive integer k ≤ n k≤n k≤n.
In one operation you can choose two indices i i i and j j j ( 1 ≤ i < j ≤ n ) (1≤i<j≤n) (1≤i<j≤n) and swap p i p_i pi with p j p_j pj.
Find the minimum number of operations needed to make the sum p 1 + p 2 + … + p k p_1+p_2+…+p_k p1+p2+…+pk as small as possible.
A permutation is an array consisting of n n n distinct integers from 1 to n n n in arbitrary order. For example, [ 2 , 3 , 1 , 5 , 4 ] [2,3,1,5,4] [2,3,1,5,4] is a permutation, but [ 1 , 2 , 2 ] [1,2,2] [1,2,2] is not a permutation ( 2 2 2 appears twice in the array) and [ 1 , 3 , 4 ] [1,3,4] [1,3,4] is also not a permutation ( n = 3 n=3 n=3 but there is 4 4 4 in the array).
题面翻译
给出一个长度为 n n n的排列 p 1 , p 2 , . . . , p n p_1,p_2,...,p_n p1,p2,...,pn和一个正整数 k k k。
在每一次操作中,你可以交换任意的 a i , a j ( 1 ≤ i , j ≤ n ) a_i,a_j(1 \le i,j \le n) ai,aj(1≤i,j≤n)。
求当 p 1 + p 2 + . . . + p k p_1+p_2+...+p_k p1+p2+...+pk最小时,最少的操作次数。
定义:排列是指有 1 1 1至 n n n组成的任意排序。例如, [ 2 , 3 , 1 , 5 , 4 ] [2,3,1,5,4] [2,3,1,5,4]是一个排列,但 [ 1 , 2 , 2 ] [1,2,2] [1,2,2]不是排列( 2 2 2在数组中出现两次), [ 1 , 3 , 4 ] [1,3,4] [1,3,4]也不是排列( n = 3 n=3 n=3但 4 4 4也在数组中)。
Input
Each test contains multiple test cases. The first line contains the number of test cases t ( 1 ≤ t ≤ 100 ) t (1≤t≤100) t(1≤t≤100). Description of the test cases follows.
The first line of each test case contains two integers n n n and k ( 1 ≤ k ≤ n ≤ 100 ) k (1≤k≤n≤100) k(1≤k≤n≤100).
The second line of each test case contains n n n integers p 1 , p 2 , … , p n ( 1 ≤ p i ≤ n ) p_1,p_2,…,p_n (1≤p_i≤n) p1,p2,…,pn(1≤pi≤n). It is guaranteed that the given numbers form a permutation of length n n n.
Output
For each test case print one integer — the minimum number of operations needed to make the sum p 1 + p 2 + … + p k p_1+p_2+…+p_k p1+p2+…+pk