#C10064. Maximum Longest Arithmetic Subsequence after Moves

    ID: 39228 Type: Default 1000ms 256MiB

Maximum Longest Arithmetic Subsequence after Moves

Maximum Longest Arithmetic Subsequence after Moves

You are given a list of (N) integers and an integer (K) that denotes the maximum number of removals allowed. In one move, you can remove exactly one element from the list. Your task is to determine the maximum length of the longest arithmetic subsequence (LAS) that can be obtained after performing at most (K) moves.

An arithmetic subsequence of an array is a sequence that can be derived by removing some elements (possibly none) such that the difference between consecutive elements is constant, i.e., for a sequence (a_1, a_2, \ldots, a_m), it holds that (a_{i+1} - a_i = d) for all (1 \le i < m) for some constant (d).

Note: The subsequence is not required to be contiguous. The input list size (N) is small enough that an exponential solution is acceptable.

inputFormat

The input is read from standard input (stdin) and consists of two lines. The first line contains two integers (N) and (K), where (N) is the number of elements and (K) is the maximum number of removals. The second line contains (N) space-separated integers representing the list.

outputFormat

Output a single integer representing the maximum length of the longest arithmetic subsequence after performing at most (K) removals. The output should be written to standard output (stdout).## sample

6 2
4 7 10 6 3 11
3