#K32717. Remaining Cards and Sum

    ID: 24928 Type: Default 1000ms 256MiB

Remaining Cards and Sum

Remaining Cards and Sum

In this problem, you are given a stack of N cards numbered from 1 to N and a given drawing order. The drawing order is represented by a list L of N integers where each integer is unique and denotes the card drawn in that order. You are also given an integer M representing the number of draws performed from the top of the stack. Your task is to determine the list of remaining cards (i.e. the cards that have not been drawn) in ascending order and compute their sum.

The problem can be mathematically described as follows:

Given (N \in \mathbb{N}), a permutation (L = [l_1, l_2, \dots, l_N]) of ({1, 2, \dots, N}), and an integer (M\ (0 \le M \le N)), define the set of drawn cards as (D = {l_1, l_2, \dots, l_M}). The remaining cards are given by (R = { x \in {1, 2, \dots, N} : x \notin D }). Your task is to output the sorted list of elements in (R) and also compute the sum (S = \sum_{x \in R} x).

Your solution should read input from standard input (stdin) and write output to standard output (stdout).

inputFormat

The input begins with an integer (T) denoting the number of test cases. For each test case, the first line contains two integers (N) and (M) where (N) is the total number of cards and (M) is the number of draws. The second line contains (N) space-separated integers representing the drawing order of the cards.

outputFormat

For each test case, output two lines. The first line should contain the remaining cards in ascending order separated by a single space (if no card remains, this line will be empty). The second line should contain the sum of these remaining cards.## sample

3
5 3
3 1 5 2 4
4 2
1 3 4 2
6 5
6 5 4 3 2 1
2 4

6 2 4 6 1 1

</p>