#P16842. [GKS 2021 #B] Longest Progression

    ID: 19169 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划 DP2021分类讨论Google Kick Start

[GKS 2021 #B] Longest Progression

Problem Description

In Kick Start 20202020 Round EE (you do not need to know anything about the previous problem to solve this one) Sarasvati learned about arithmetic arrays. An arithmetic array is an array that contains at least 22 integers and the differences between consecutive integers are equal. For example, [9,10][9, 10], [3,3,3][3, 3, 3], and [9,7,5,3][9, 7, 5, 3] are arithmetic arrays, while [1,3,3,7][1, 3, 3, 7], [2,1,2][2, 1, 2], and [1,2,4][1, 2, 4] are not.

Sarasvati again has an array of NN non-negative integers. The ii-th integer of the array is AiA_i. She can replace at most 11 element in the array with any (possibly negative) integer she wants.

For an array AA, Sarasvati defines a subarray as any contiguous part of AA. Please help Sarasvati determine the length of the longest possible arithmetic subarray she can create by replacing at most 11 element in the original array.

Input Format

The first line of the input gives the number of test cases, TT. TT test cases follow. Each test case begins with a line containing the integer NN. The second line contains NN integers. The ii-th integer is AiA_i.

Output Format

For each test case, output one line containing Case #x: followed by yy, where xx is the test case number (starting from 11) and yy is the length of the longest arithmetic subarray.

3
4
9 7 5 3
9
5 5 4 5 5 5 4 5 6
4
8 5 2 0
Case #1: 4
Case #2: 6
Case #3: 4

Hint

In Sample Case #11, the whole array is an arithmetic array, thus the longest arithmetic subarray is the whole array.

In Sample Case #22, if Sarasvati changes the number at third position to 55, the array will become [5,5,5,5,5,5,4,5,6][5, 5, 5, 5, 5, 5, 4, 5, 6]. The subarray from first position to sixth position is the longest arithmetic subarray.

In Sample Case #33, Sarasvati can change the number at the last position to 1-1, to get [8,5,2,1][8, 5, 2, -1]. This resulting array is arithmetic.

Limits

1T1001 \le T \le 100.

0Ai1090 \le A_i \le 10^9.

Test Set 11

2N20002 \le N \le 2000.

Test Set 22

2N3×1052 \le N \le 3 \times 10^5 for at most 1010 test cases.

For the remaining cases, 2N20002 \le N \le 2000.