A9422 | k-d-sequence
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
We'll call a sequence of integers a good $k$ - $d$ sequence if we can add to it at most $k$ numbers in such a way that after the sorting the sequence will be an arithmetic progression with difference $d$ .
You got hold of some sequence $a$ , consisting of $n$ integers. Your task is to find its longest contiguous subsegment, such that it is a good $k$ - $d$ sequence.
You got hold of some sequence $a$ , consisting of $n$ integers. Your task is to find its longest contiguous subsegment, such that it is a good $k$ - $d$ sequence.
输入格式
The first line contains three space-separated integers $n,k,d$ ( $1<=n<=2·10^{5}; 0<=k<=2·10^{5}; 0<=d<=10^{9}$ ). The second line contains $n$ space-separated integers: $a_{1},a_{2},...,a_{n}$ ( $-10^{9}<=a_{i}<=10^{9}$ ) — the actual sequence.
输出格式
Print two space-separated integers $l,r$ ( $1<=l<=r<=n$ ) show that sequence $a_{l},a_{l+1},...,a_{r}$ is the longest subsegment that is a good $k$ - $d$ sequence.
If there are multiple optimal answers, print the one with the minimum value of $l$ .
If there are multiple optimal answers, print the one with the minimum value of $l$ .
输入输出样例
输入 #1
6 1 2 4 3 2 8 6 2
输出 #1
3 5
In the first test sample the answer is the subsegment consisting of numbers 2, 8, 6 — after adding number 4 and sorting it becomes sequence 2, 4, 6, 8 — the arithmetic progression with difference 2.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted