309642: CF1712A. Wonderful Permutation

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Wonderful Permutation

题意翻译

## 题意描述 给你一个 $n$ 的排列 $p_i$ 以及 $k (k \le n)$。 在一次操作中,你可以选择两个编号 $i,j$ 并且交换 $p_i,p_j$。 求最少需要几次操作才能使 $\sum\limits_{i=1}\limits^{k} p_i$ 的值最小。 排列是指由 $n$ 个 $1$ 到 $n$ 的不同整数按任意顺序组成的序列,序列中不能有重复的数字,也不能有大于 $n$ 的数。 ## 输入格式 每个测试点都有多组数据。 第一行一个正整数 $t(1 \le t \le 100)$ 表示数据组数。 对于每一组数据,第一行两个正整数 $n,k(1 \le n,k \le 100)$。 接着一行,一个 $n$ 的排列,表示 $p$ 数组。 ## 输出格式 对于每次询问,一行一个数,表示使得 $\sum\limits_{i=1}\limits^{k}$ 最小所需要的最少操作次数。

题目描述

God's Blessing on This PermutationForces! A Random Pebble You are given a permutation $ p_1,p_2,\ldots,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 < j \le n $ ) and swap $ p_i $ with $ p_j $ . Find the minimum number of operations needed to make the sum $ p_1 + p_2 + \ldots + 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, $ [2,3,1,5,4] $ is a permutation, but $ [1,2,2] $ is not a permutation ( $ 2 $ appears twice in the array) and $ [1,3,4] $ is also not a permutation ( $ n=3 $ but there is $ 4 $ in the array).

输入输出格式

输入格式


Each test contains multiple test cases. The first line contains the number of test cases $ t $ ( $ 1 \le t \le 100 $ ). 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,\ldots,p_n $ ( $ 1 \le p_i \le n $ ). It is guaranteed that the given numbers form a permutation of length $ n $ .

输出格式


For each test case print one integer — the minimum number of operations needed to make the sum $ p_1 + p_2 + \ldots + p_k $ as small as possible.

输入输出样例

输入样例 #1

4
3 1
2 3 1
3 3
1 2 3
4 2
3 4 1 2
1 1
1

输出样例 #1

1
0
2
0

说明

In the first test case, the value of $ p_1 + p_2 + \ldots + p_k $ is initially equal to $ 2 $ , but the smallest possible value is $ 1 $ . You can achieve it by swapping $ p_1 $ with $ p_3 $ , resulting in the permutation $ [1, 3, 2] $ . In the second test case, the sum is already as small as possible, so the answer is $ 0 $ .

Input

题意翻译

## 题意描述 给你一个 $n$ 的排列 $p_i$ 以及 $k (k \le n)$。 在一次操作中,你可以选择两个编号 $i,j$ 并且交换 $p_i,p_j$。 求最少需要几次操作才能使 $\sum\limits_{i=1}\limits^{k} p_i$ 的值最小。 排列是指由 $n$ 个 $1$ 到 $n$ 的不同整数按任意顺序组成的序列,序列中不能有重复的数字,也不能有大于 $n$ 的数。 ## 输入格式 每个测试点都有多组数据。 第一行一个正整数 $t(1 \le t \le 100)$ 表示数据组数。 对于每一组数据,第一行两个正整数 $n,k(1 \le n,k \le 100)$。 接着一行,一个 $n$ 的排列,表示 $p$ 数组。 ## 输出格式 对于每次询问,一行一个数,表示使得 $\sum\limits_{i=1}\limits^{k}$ 最小所需要的最少操作次数。

Output

**题目大意:**

给定一个长度为 $ n $ 的排列 $ p_1, p_2, \ldots, p_n $ 和一个正整数 $ k \le n $。通过交换 $ p_i $ 和 $ p_j $($ 1 \le i < j \le n $)的操作,求使 $ p_1 + p_2 + \ldots + p_k $ 的和最小所需的最少操作次数。

**输入格式:**

每个测试点包含多个测试案例。第一行包含测试案例的数量 $ t $($ 1 \le t \le 100 $)。随后是每个测试案例的描述。

每个测试案例的第一行包含两个整数 $ n $ 和 $ k $($ 1 \le k \le n \le 100 $)。

每个测试案例的第二行包含 $ n $ 个整数 $ p_1, p_2, \ldots, p_n $($ 1 \le p_i \le n $)。保证给定的数字构成一个长度为 $ n $ 的排列。

**输出格式:**

对于每个测试案例,输出一个整数——使 $ p_1 + p_2 + \ldots + p_k $ 的和最小所需的最少操作次数。**题目大意:** 给定一个长度为 $ n $ 的排列 $ p_1, p_2, \ldots, p_n $ 和一个正整数 $ k \le n $。通过交换 $ p_i $ 和 $ p_j $($ 1 \le i < j \le n $)的操作,求使 $ p_1 + p_2 + \ldots + p_k $ 的和最小所需的最少操作次数。 **输入格式:** 每个测试点包含多个测试案例。第一行包含测试案例的数量 $ t $($ 1 \le t \le 100 $)。随后是每个测试案例的描述。 每个测试案例的第一行包含两个整数 $ n $ 和 $ k $($ 1 \le k \le n \le 100 $)。 每个测试案例的第二行包含 $ n $ 个整数 $ p_1, p_2, \ldots, p_n $($ 1 \le p_i \le n $)。保证给定的数字构成一个长度为 $ n $ 的排列。 **输出格式:** 对于每个测试案例,输出一个整数——使 $ p_1 + p_2 + \ldots + p_k $ 的和最小所需的最少操作次数。

加入题单

算法标签: