题目链接

On February 14, Denis decided to give a Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length k (k≥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,…,an in order from left to right (k≤n). It is guaranteed that neighboring heights are not equal to each other (that is, ai≠ai+1 for all i from 1 to n−1).

Peaks of mountains on the segment [l,r] (from l to r) are called indexes i such that l<i<r, ai−1ai+1. It is worth noting that the boundary indexes l and r for the segment are not peaks. For example, if n=8 and a=[3,1,4,1,5,9,2,6], then the segment [1,8] has only two peaks (with indexes 3 and 6), and there are no peaks on the segment [3,6].

To break the door, Nastya throws it to a segment [l,l+k−1] of consecutive mountains of length k (1≤l≤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+1, where p is the number of peaks on the segment [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] that the number of peaks on it is maximum. If there are several optimal segments, Nastya wants to find one for which the value l is minimal.

Formally, you need to choose a segment of mountains [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 l.

Input

The first line contains an integer t (1≤t≤1e4) — the number of test cases. Then the descriptions of the test cases follow.

The first line of each test case contains two integers n and k (3≤k≤n≤2e5) — the number of mountains and the length of the door.

The second line of the input data set contains n integers a1,a2,…,an (0≤ai≤1e9, ai≠ai+1) — the heights of mountains.

It is guaranteed that the sum of n over all the test cases will not exceed 2e5.

Output

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

Example

input

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

output

3 2
2 2
2 1
3 1
2 3

很明显的后缀和问题~
我们用 p r e [ i ] pre[i] pre[i] 表示从当前位置到最后位置的山峰的数量,那么对当前位置 i i i,在 [ i , i + k − 1 ] [i,i+k-1] [i,i+k−1] 范围中山峰的数量就为 p r e [ i + k ] − p r e [ i ] pre[i+k]-pre[i] pre[i+k]−pre[i],此时已经对了一大半了,题目要求边界不做考虑,所以我们还要标记一下,减去边界即可。对了,这题有个坑点,输出的位置要初始化为1,否则会WA,估计是有没有山峰的数据,真的无语(ˉ▽ˉ;)…,AC代码如下:

#include <bits/stdc++.h>using namespace std;
typedef long long ll;int main() {int t, n, k;cin >> t;while (t--) {cin >> n >> k;int a[n + 1], pre[n + k + 2] = {0};map<int, int> m;for (int i = 1; i <= n; i++) cin >> a[i];for (int i = 2; i <= n - 1; i++) {if (a[i] > a[i - 1] && a[i] > a[i + 1]) {m[i] = 1;pre[i] = 1;}}for (int i = n + k; i >= 1; i--) {pre[i] += pre[i + 1];}int minpos = 1, maxnum = 0;for (int i = 1; i <= n; i++) {int p = pre[i] - pre[i + k] - m[i] - m[i + k - 1];if (p > maxnum) {maxnum = p;minpos = i;}}cout << maxnum + 1 << " " << minpos << endl;}return 0;
}

Codeforces Round #637 (Div. 2) - Thanks, Ivan Belonogov! B.Nastya and Door相关推荐

  1. Codeforces Round #637 (Div. 2) - Thanks, Ivan Belonogov! C. Nastya and Strange Generator

    题目链接 Being upset after this behavior of Nastya, Denis was very sad. Nothing could make the rejected ...

  2. Codeforces Round #637 (Div. 2) - Thanks, Ivan Belonogov! D. Nastya and Scoreboard题解(记忆化搜索)

    题目链接 题目大意 一个n个数码位的分数板,每一个数码位都是一个七段数码管,现在给出每个数码位的显示情况,问再点亮k段数码管的话能显示的最大的数是多少,如果不能构成一串数字,就输出-1.答案允许有前导 ...

  3. 欠债还钱、Codeforces Round #637 (Div. 2) -D(多重背包)

    Description llk经常和wy一起去yh小饭馆吃盖浇饭,一天他们吃完后llk把两个人的钱一起付了,但是wy不想欠llk的钱.现在wy手中有一些散钱,llk手中也有一些散钱,wy想知道能不能刚 ...

  4. Codeforces Round #594 (Div. 2) C. Ivan the Fool and the Probability Theory 思维 + dp

    文章目录 题意: 思路 题意: 思路 一开始找规律,表都打好了,没找出来.. 找规律还是适合让队友来. 先考虑第一行,我们先计算第一行的方案数,设f[i][j]f[i][j]f[i][j]表示到了ii ...

  5. 【Codeforces Round #532 (Div. 2) F. Ivan and Burgers】离线+线性基

    F. Ivan and Burgers 题意 n个数,q次询问,每次询问一个区间内选出任意个数的异或最大值. 1<=n<=5∗1051<=n<=5*10^51<=n< ...

  6. Codeforces Round #532 (Div. 2) F. Ivan and Burgers(可持久化异或线性基+双指针)

    题意 给n个数,q组询问,每次询问l到r的最大异或和 思路来源 某cf奆神代码 题解 本来应该是线性基上分治的 这里一发基数+贪心也能过 真是神仙代码啊 双指针的经典应用: 对于每个询问[l,r],r ...

  7. Codeforces Round #637 (Div. 2) C. Nastya and Strange Generator 题解(阅读理解+简单思维)

    题目链接 题目大意 真难读 问给定的序列能不能用题中所给的算法生成. 比如,题目中举的例子:原序列a: [ 2 3 * * 1 ],先得出 r 数组 [ 3, 3 ,3 ,4 , * ] .r 数组的 ...

  8. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  9. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

最新文章

  1. 【CentOS 7LNMP架构33】,nginx负载均衡#180109
  2. BUUCTF(pwn)hgame2018_flag_server(简单的栈溢出)
  3. 怎么html中加样式,简明教程 在HTML中添加样式表的方法
  4. TensorFlow(五)常用函数与基本操作
  5. .NET 3.5(11) - DLINQ(LINQ to SQL)之大数据量分页、延迟执行和日志记录
  6. 第15条:使可变性最小化
  7. python课堂随机点名_【工作中的Python】随机点名小脚本
  8. SAP物料编码- -
  9. 使用brew services管理服务
  10. VIVADO synthesis和implementation具体完成什么操作
  11. 朋友圈/评论/点赞/搜索/购物车
  12. 计算机网络知识面试常考
  13. park停车场项目实战
  14. MySQL中的字符集是啥?如何更改?
  15. JDK1.7扩容时为什么会产生并发死链问题
  16. linux下.tar.gz如何解压
  17. 燕十八 mysql_布尔教育燕十八mysql优化视频课件源码分享
  18. matlab 大数,在Matlab中考虑大数,然后得到结果中的数字
  19. 冒泡排序(C++)完整代码
  20. java 计算百分比值

热门文章

  1. 手动将jar加入到maven仓库
  2. fileZilla的使用心得
  3. Android获取手机型号、系统版本号、手机IMEI、手机厂商等
  4. 在武汉,想和你一起做的100件事
  5. 2021年全国房地产200强企业销售额分析:房地产101-200强企业销售总额17085.7亿元[图]
  6. CSR8670获取来电号码及开发流程
  7. 大文件上传时如何做到秒传?(荣耀典藏版)
  8. 使用Spring的AOP实现接口方法执行时间记录
  9. 云呐:医院固定资产管理存在的问题及原因,资产管理系统的实施
  10. stata 将数据集变量名称导出_一文读懂空间计量经济学及stata操作