#K38982. Subsequence Arithmetic Progression

    ID: 26319 Type: Default 1000ms 256MiB

Subsequence Arithmetic Progression

Subsequence Arithmetic Progression

You are given a list of m integers and two additional integers: n and d. Your task is to determine whether there exists a subsequence of length n that can be rearranged to form an arithmetic progression with common difference d. In other words, you need to check if there exists a number a in the list such that the numbers

a,  a+d,  a+2d,  ,  a+(n1)da,\;a+d,\;a+2d,\;\dots,\;a+(n-1)d

all appear in the list. Note that when d = 0, the problem reduces to checking whether any number appears at least n times.

It is guaranteed that if n = 1, the answer is always True.

inputFormat

The input is provided via stdin and consists of two lines:

  • The first line contains three space-separated integers: m (m is the total number of elements), n (the length of the subsequence), and d (the common difference).
  • The second line contains m space-separated integers representing the list.

outputFormat

Output a single line to stdout: True if there exists a subsequence of length n that can form an arithmetic progression with common difference d, and False otherwise.

## sample
6 3 2
3 5 1 7 9 11
True

</p>