CF1341B.Nastya and Door

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length kk (k≥3k \ge 3). Nastya was very confused by this present, so she decided to break the door, throwing it on the mountains.

Mountains are described by a sequence of heights a1,a2,…,ana_1, a_2, \dots, a_n in order from left to right (k≤nk \le n). It is guaranteed that neighboring heights are not equal to each other (that is, ai≠ai+1a_i \ne a_{i+1} for all ii from 11 to n−1n-1).

Peaks of mountains on the segment [l,r][l,r] (from ll to rr) are called indexes ii such that l<i<rl \lt i \lt r, ai−1<aia_{i - 1} \lt a_i and ai>ai+1a_i \gt a_{i + 1}. It is worth noting that the boundary indexes ll and rr for the segment are not peaks. For example, if n=8n=8 and a=[3,1,4,1,5,9,2,6]a=[3,1,4,1,5,9,2,6], then the segment [1,8][1,8] has only two peaks (with indexes 33 and 66), and there are no peaks on the segment [3,6][3, 6].

To break the door, Nastya throws it to a segment [l,l+k−1][l,l+k-1] of consecutive mountains of length kk (1≤l≤n−k+11 \le l \le n-k+1). When the door touches the peaks of the mountains, it breaks into two parts, after that these parts will continue to fall in different halves and also break into pieces when touching the peaks of the mountains, and so on. Formally, the number of parts that the door will break into will be equal to p+1p+1, where pp is the number of peaks on the segment [l,l+k−1][l,l+k-1].

Nastya wants to break it into as many pieces as possible. Help her choose such a segment of mountains [l,l+k−1][l, l+k-1] that the number of peaks on it is maximum. If there are several optimal segments, Nastya wants to find one for which the value ll is minimal.

Formally, you need to choose a segment of mountains [l,l+k−1][l, l+k-1] that has the maximum number of peaks. Among all such segments, you need to find the segment that has the minimum possible value ll.

2月14日,丹尼斯决定送给娜斯佳一份情人节礼物,却想不出比在长度为 kk(k≥3k \ge 3)的门上画一个巨大的红色爱心更好的主意。娜斯佳对这份礼物感到十分困惑,于是决定把门砸向群山以将其毁掉。

群山由从左到右排列的高度序列 a1,a2,…,ana_1, a_2, \dots, a_n 描述(其中 k≤nk \le n)。保证相邻高度互不相等(即对所有 i=1,2,…,n−1i = 1, 2, \dots, n-1,均有 ai≠ai+1a_i \ne a_{i+1})。

对于区间 [l,r][l,r](即从 ll 到 rr),其山峰定义为满足 l<i<rl \lt i \lt r、ai−1<aia_{i - 1} \lt a_i 且 ai>ai+1a_i \gt a_{i + 1} 的下标 ii。注意:区间的端点下标 ll 和 rr 不视为山峰。例如,若 n=8n=8 且 a=[3,1,4,1,5,9,2,6]a=[3,1,4,1,5,9,2,6],则区间 [1,8][1,8] 仅有两个山峰(下标为 33 和 66),而区间 [3,6][3,6] 上没有山峰。

为了砸碎这扇门,娜斯佳将它扔向一段长度为 kk 的连续山峰区间 [l,l+k−1][l,l+k-1](其中 1≤l≤n−k+11 \le l \le n-k+1)。当门接触到山峰时,会断裂为两部分;随后这两部分继续向左右两侧下落,并在再次接触山峰时继续分裂,依此类推。形式化地,门最终分裂成的碎片数量等于 p+1p+1,其中 pp 是区间 [l,l+k−1][l,l+k-1] 上的山峰个数。

娜斯佳希望将门分裂成尽可能多的碎片。请帮她选择一个山峰数量最多的区间 [l,l+k−1][l, l+k-1]。如果存在多个最优区间,则娜斯佳希望选择其中 ll 值最小的那个。

形式化地说,你需要选择一个山峰数量最多的山峰区间 [l,l+k−1][l, l+k-1];在所有满足该条件的区间中,找出 ll 值最小的那个区间。

输入格式

The first line contains an integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases. Then the descriptions of the test cases follow.

The first line of each test case contains two integers nn and kk (3≤k≤n≤2⋅1053 \leq k \leq n \leq 2 \cdot 10^5) — the number of mountains and the length of the door.

The second line of the input data set contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (0≤ai≤1090 \leq a_i \leq 10 ^ 9, ai≠ai+1a_i \neq a_{i + 1}) — the heights of mountains.

It is guaranteed that the sum of nn over all the test cases will not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4)—— 测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 kk(3≤k≤n≤2⋅1053 \leq k \leq n \leq 2 \cdot 10^5)—— 山峰的数量和门的长度。

输入数据集的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(0≤ai≤1090 \leq a_i \leq 10 ^ 9,且 ai≠ai+1a_i \neq a_{i + 1})—— 各山峰的高度。

保证所有测试用例的 nn 值之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output two integers tt and ll — the maximum number of parts that the door can split into, and the left border of the segment of length kk that the door should be reset to.

对于每个测试用例,输出两个整数 tt 和 ll —— 门最多能被分割成的部分数,以及门应重置到的长度为 kk 的区间的左边界。

输入输出样例

  • 输入#1

    5
    8 6
    1 2 4 1 2 4 1 2
    5 3
    3 2 3 2 1
    10 4
    4 3 4 3 2 3 2 1 0 1
    15 7
    3 7 4 8 2 3 4 5 21 2 3 4 2 1 3
    7 5
    1 2 3 4 5 6 1

    输出#1

    3 2
    2 2
    2 1
    3 1
    2 3

说明/提示

In the first example, you need to select a segment of mountains from 22 to 77. In this segment, the indexes 33 and 66 are peaks, so the answer is 33 (only 22 peaks, so the door will break into 33 parts). It is not difficult to notice that the mountain segments [1,6][1, 6] and [3,8][3, 8] are not suitable since they only have a 11 peak (for the first segment, the 66 index is not a peak, and for the second segment, the 33 index is not a peak).

In the second example, you need to select a segment of mountains from 22 to 44. In this segment, the index 33 is a peak, so the answer is 22 (only 11 peak, so the door will break into 22 parts).

In the third example, you need to select a segment of mountains from 11 to 44. In this segment, the index 33 is a peak, so the answer is 22 (only 11 peak, so the door will break into 22 parts). You can see that on the segments [2,5][2, 5], [4,7][4, 7] and [5,8][5, 8] the number of peaks is also 11, but these segments have a left border greater than the segment [1,4][1, 4], so they are not the correct answer.

在第一个例子中,你需要选择从第 22 座到第 77 座山构成的山段。在此山段中,索引 33 和 66 是峰,因此答案为 33(仅有 22 个峰,故门将碎裂为 33 块)。不难注意到,山段 [1,6][1, 6] 和 [3,8][3, 8] 均不满足要求,因为它们各自仅含 11 个峰(对第一个山段而言,索引 66 不是峰;对第二个山段而言,索引 33 不是峰)。

在第二个例子中,你需要选择从第 22 座到第 44 座山构成的山段。在此山段中,索引 33 是峰,因此答案为 22(仅有 11 个峰,故门将碎裂为 22 块)。

在第三个例子中,你需要选择从第 11 座到第 44 座山构成的山段。在此山段中,索引 33 是峰,因此答案为 22(仅有 11 个峰,故门将碎裂为 22 块)。可以看出,在山段 [2,5][2, 5]、[4,7][4, 7] 和 [5,8][5, 8] 上峰的数量同样为 11,但这些山段的左端点均大于山段 [1,4][1, 4] 的左端点,因此它们不是正确答案。

输入解题思路,AI测评打分。不知道怎么写?

首页