#C8680. Sequence Summation Problem

    ID: 52689 Type: Default 1000ms 256MiB

Sequence Summation Problem

Sequence Summation Problem

You are given an initial list of integers and two numbers, \(M\) and \(N\). Your task is to generate a sequence of length \(M\) by repeatedly appending the smallest positive integer that is missing from the current sequence. After the sequence has reached the required length, compute and output the sum of its first \(N\) elements.

For example, if the initial list is [3, 1, 6], \(M=8\) and \(N=5\), then the process is as follows:

  • Initial sequence: [3, 1, 6]
  • The smallest missing positive integer is 2, so append it: [3, 1, 6, 2]
  • Now the missing integer is 4: [3, 1, 6, 2, 4]
  • Then 5: [3, 1, 6, 2, 4, 5]
  • Then 7: [3, 1, 6, 2, 4, 5, 7]
  • Finally 8: [3, 1, 6, 2, 4, 5, 7, 8]

The answer is the sum of the first \(N=5\) elements, i.e. \(3 + 1 + 6 + 2 + 4 = 16\).

Note: All input will be read from standard input (stdin) and all output should be written to standard output (stdout).

inputFormat

The input consists of two lines:

  • The first line contains three integers \(M\), \(N\), and \(K\) separated by spaces, where \(M\) is the desired length of the sequence, \(N\) is the number of elements to sum and \(K\) is the number of elements in the initial list.
  • The second line contains \(K\) space-separated integers representing the initial list.

outputFormat

Output a single integer which is the sum of the first \(N\) numbers of the generated sequence.

## sample
8 5 3
3 1 6
16