CF487B.Strip
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Alexandra has a paper strip with n numbers on it. Let's call them a__i from left to right.
Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy:
- Each piece should contain at least l numbers.
- The difference between the maximal and the minimal number on the piece should be at most s.
Please help Alexandra to find the minimal number of pieces meeting the condition above.
亚历山德拉有一条纸带,上面从左到右依次写着 n 个数字,记为 ai。
现在亚历山德拉想将这条纸带分割成若干段(可能只有一段)。每一段必须满足以下条件:
- 每段至少包含 l 个数字;
- 每段中最大值与最小值之差至多为 s。
请帮助亚历山德拉找出满足上述条件的最少段数。
输入格式
The first line contains three space-separated integers n, s, l (1 ≤ n ≤ 105, 0 ≤ s ≤ 109, 1 ≤ l ≤ 105).
The second line contains n integers a__i separated by spaces ( - 109 ≤ a__i ≤ 109).
第一行包含三个以空格分隔的整数 n、s、l(1 ≤ n ≤ 105,0 ≤ s ≤ 109,1 ≤ l ≤ 105)。
第二行包含 n 个以空格分隔的整数 ai(−109 ≤ ai ≤ 109)。
输出格式
Output the minimal number of strip pieces.
If there are no ways to split the strip, output -1.
输出分割条带所需的最少段数。
如果无法分割该条带,则输出 -1。
输入输出样例
输入#1
7 2 2 1 3 1 2 4 1 2
输出#1
3
输入#2
7 2 2 1 100 1 100 1 100 1
输出#2
-1
说明/提示
For the first sample, we can split the strip into 3 pieces: [1, 3, 1], [2, 4], [1, 2].
For the second sample, we can't let 1 and 100 be on the same piece, so no solution exists.
对于第一个样例,我们可以将纸条分割成 3 段:[1, 3, 1], [2, 4], [1, 2]。
对于第二个样例,我们不能让 1 和 100 出现在同一段中,因此不存在可行解。
输入解题思路,AI测评打分。不知道怎么写?