CF1704B.Luke is a Foodie

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Luke likes to eat. There are nn piles of food aligned in a straight line in front of him. The ii-th pile contains aia_i units of food.

Luke will walk from the 11-st pile towards the nn-th pile, and he wants to eat every pile of food without walking back. When Luke reaches the ii-th pile, he can eat that pile if and only if ∣v−ai∣≤x|v - a_i| \leq x, where xx is a fixed integer, and vv is Luke's food affinity.

Before Luke starts to walk, he can set vv to any integer. Also, for each ii (1≤i≤n1 \leq i \leq n), Luke can change his food affinity to any integer before he eats the ii-th pile.

Find the minimum number of changes needed to eat every pile of food.

Note that the initial choice for vv is not considered as a change.

卢克喜欢吃东西。他面前有一条直线上排列着 nn 堆食物,其中第 ii 堆含有 aia_i 单位的食物。

卢克将从第 11 堆出发,依次走向第 nn 堆,并且他希望在不回头的情况下吃掉所有食物堆。当卢克到达第 ii 堆时,他仅当满足 ∣v−ai∣≤x|v - a_i| \leq x 时才能吃掉该堆食物,其中 xx 是一个给定的固定整数,而 vv 是卢克当前的食物亲和力(food affinity)。

在卢克开始行走前,他可以将 vv 初始化为任意整数。此外,对每个 ii(1≤i≤n1 \leq i \leq n),卢克可以在吃第 ii 堆食物之前将他的食物亲和力 vv 改为任意整数。

请找出吃掉所有食物堆所需的最少修改次数。

注意:初始设定 vv 的值不计为一次修改。

输入格式

The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases. The description of test cases follows.

For each test case, the first line contains two integers, n,xn, x (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5, 1≤x≤1091 \leq x \leq 10^9) — the number of piles, and the maximum difference between the size of a pile and Luke's food affinity, such that Luke can eat the pile.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots , a_n (1≤ai≤1091 \leq a_i \leq 10^9).

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

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

对于每个测试用例,第一行包含两个整数 nn 和 xx(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5,1≤x≤1091 \leq x \leq 10^9)—— 分别表示堆的数量,以及 Luke 能吃掉某堆食物所允许的该堆大小与 Luke 的食物亲和力之间的最大差值。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots , a_n(1≤ai≤1091 \leq a_i \leq 10^9)。

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

输出格式

For each test case, output an integer on a separate line, which is the minimum number of changes needed.

对于每个测试用例,在单独一行输出一个整数,表示所需的最少修改次数。

输入输出样例

  • 输入#1

    7
    5 3
    3 8 5 6 7
    5 3
    3 10 9 8 7
    12 8
    25 3 3 17 8 6 1 16 15 25 17 23
    10 2
    1 2 3 4 5 6 7 8 9 10
    8 2
    2 4 6 8 6 4 12 14
    8 2
    2 7 8 9 6 13 21 28
    15 5
    11 4 13 23 7 10 5 21 20 11 17 5 29 16 11

    输出#1

    0
    1
    2
    1
    2
    4
    6

说明/提示

In the first test case, Luke can set vv to 55 before he starts to walk. And he can walk straight to eat every piles of food without changing vv.

In the second test case, Luke can set vv to 33 before he starts to walk. And he could change vv to 1010 before he eats the second pile. After that, he can walk straight to eat remaining food without changing vv.

In the fourth test case, Luke can set vv to 33 before he starts to walk. And he could change vv to 88 before he eats the sixth pile. After that, he can walk straight to eat remaining food without changing vv.

In the fifth test case, Luke can set vv to 44 before he starts to walk. And he could change vv to 66 before he eats the fourth pile. Then he could change vv to 1212 before he eats the seventh pile. After that, he can walk straight to eat remaining food without changing vv.

在第一个测试用例中,Luke 可以在开始行走前将 vv 设为 55,之后他可以保持 vv 不变,沿直线行走并吃掉所有堆食物。

在第二个测试用例中,Luke 可以在开始行走前将 vv 设为 33,并在吃第二堆食物前将 vv 改为 1010;此后,他可以保持 vv 不变,沿直线行走并吃掉剩余的食物。

在第四个测试用例中,Luke 可以在开始行走前将 vv 设为 33,并在吃第六堆食物前将 vv 改为 88;此后,他可以保持 vv 不变,沿直线行走并吃掉剩余的食物。

在第五个测试用例中,Luke 可以在开始行走前将 vv 设为 44,并在吃第四堆食物前将 vv 改为 66,再在吃第七堆食物前将 vv 改为 1212;此后,他可以保持 vv 不变,沿直线行走并吃掉剩余的食物。

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

首页