#P13631. [NWRRC 2021] Day Streak

    ID: 15478 远端评测题 4000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>线段树2021Special JudgeICPC双指针 two-pointerNWRRC

[NWRRC 2021] Day Streak

题目描述

Recently Deltaforces, a famous competitive programming website, added a lot of new visual information to user profiles. In particular, there is a maximum day streak --- the maximum number of days in a row with at least one problem solved. You decided that the maximum day streak in your profile does not accurately represent your training efforts. So you came up with a thought --- what if you could change the time zone in your profile to increase the maximum day streak?

Let's formalize this setting as follows. Suppose you have solved nn problems, and the ii-th problem was solved at time aia_i. There are mm time zones, numbered from 00 to m1m - 1. The default time zone is 00. If you decide to change your time zone to tt, all solutions' timestamps increase by tt: the problem solved at time aia_i is now considered to be solved at time ai+ta_i + t, for all ii simultaneously.

The problem solved at time xx is considered to be solved on day number xm\lfloor \frac{x}{m} \rfloor. Here v\lfloor v \rfloor means vv rounded down to the greatest integer less than or equal to vv.

To display the maximum day streak, Deltaforces finds such ll and rr that you have solved at least one problem on each of days l,l+1,,rl, l+1, \ldots, r, and rl+1r - l + 1 is as large as possible. Then your maximum day streak is shown as rl+1r - l + 1.

Find the maximum day streak you can achieve by selecting a time zone.

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1t21051 \le t \le 2 \cdot 10^5). Description of the test cases follows.

The first line of each test case contains two integers nn and mm --- the number of solved problems and the number of time zones (1n21051 \le n \le 2 \cdot 10^5; 1m1091 \le m \le 10^9). The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n --- distinct timestamps of your solutions, in chronological order (0a1<a2<<an1090 \le a_1 < a_2 < \dotsb < a_n \le 10^9).

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5.

输出格式

For each test case, print two integers ss and tt --- the maximum day streak and any time zone that achieves it (1sn1 \le s \le n; 0t<m0 \le t < m).

5
4 10
0 3 8 24
2 10
32 35
10 1
0 1 3 4 5 6 7 10 11 12
10 24
0 1 3 4 5 6 7 10 11 12
8 24
26 71 101 147 181 201 244 268
3 2
2 5
5 0
2 12
4 15

提示

In the first example test case, when you select time zone 22, the timestamps of your solutions change to 22, 55, 1010, and 2626. It means the problems are now considered to be solved on days 00, 00, 11, and 22; that is a~33-day streak. Time zones 33, 44, and 55 yield the same answer.

In the second example test case, timestamps of your solutions are 3737 and 4040 in time zone 55, which corresponds to days 33 and 44. Time zones 66 and 77 also work.

In the third example test case, only one time zone exists, and your maximum day streak is 55.

In the fourth example test case, you have solved many problems but in a short period of time, and you can't obtain more than a 22-day streak.