CF1661D.Progressions Covering

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given two arrays: an array aa consisting of nn zeros and an array bb consisting of nn integers.

You can apply the following operation to the array aa an arbitrary number of times: choose some subsegment of aa of length kk and add the arithmetic progression 1,2,…,k1, 2, \ldots, k to this subsegment — i. e. add 11 to the first element of the subsegment, 22 to the second element, and so on. The chosen subsegment should be inside the borders of the array aa (i.e., if the left border of the chosen subsegment is ll, then the condition 1≤l≤l+k−1≤n1 \le l \le l + k - 1 \le n should be satisfied). Note that the progression added is always 1,2,…,k1, 2, \ldots, k but not the k,k−1,…,1k, k - 1, \ldots, 1 or anything else (i.e., the leftmost element of the subsegment always increases by 11, the second element always increases by 22 and so on).

Your task is to find the minimum possible number of operations required to satisfy the condition ai≥bia_i \ge b_i for each ii from 11 to nn. Note that the condition ai≥bia_i \ge b_i should be satisfied for all elements at once.

你有两个数组:一个由 nn 个零组成的数组 aa,以及一个由 nn 个整数组成的数组 bb。

你可以对数组 aa 执行任意多次如下操作:选择 aa 的一个长度为 kk 的子段,并向该子段加上等差数列 1,2,…,k1, 2, \ldots, k —— 即向子段的第一个元素加 11,第二个元素加 22,依此类推。所选子段必须完全位于数组 aa 的边界内(即若所选子段的左端点为 ll,则需满足 1≤l≤l+k−1≤n1 \le l \le l + k - 1 \le n)。注意,每次所加的等差数列恒为 1,2,…,k1, 2, \ldots, k,而非 k,k−1,…,1k, k-1, \ldots, 1 或其他形式(即子段最左侧元素总是增加 11,第二个元素总是增加 22,以此类推)。

你的任务是求出满足条件 ai≥bia_i \ge b_i(对每个 i=1,2,…,ni = 1, 2, \ldots, n)所需的最少操作次数。注意,该条件需对所有元素同时成立。

输入格式

The first line of the input contains two integers nn and kk (1≤k≤n≤3⋅1051 \le k \le n \le 3 \cdot 10^5) — the number of elements in both arrays and the length of the subsegment, respectively.

The second line of the input contains nn integers b1,b2,…,bnb_1, b_2, \ldots, b_n (1≤bi≤10121 \le b_i \le 10^{12}), where bib_i is the ii-th element of the array bb.

输入的第一行包含两个整数 nn 和 kk(1≤k≤n≤3⋅1051 \le k \le n \le 3 \cdot 10^5),分别表示两个数组的元素个数以及子区间的长度。

输入的第二行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \ldots, b_n(1≤bi≤10121 \le b_i \le 10^{12}),其中 bib_i 是数组 bb 的第 ii 个元素。

输出格式

Print one integer — the minimum possible number of operations required to satisfy the condition ai≥bia_i \ge b_i for each ii from 11 to nn.

输出一个整数——满足对每个 ii(从 11 到 nn)都有 ai≥bia_i \ge b_i 所需的最少操作次数。

输入输出样例

  • 输入#1

    3 3
    5 4 6

    输出#1

    5
  • 输入#2

    6 3
    1 2 3 2 2 3

    输出#2

    3
  • 输入#3

    6 3
    1 2 4 1 2 3

    输出#3

    3
  • 输入#4

    7 3
    50 17 81 25 42 39 96

    输出#4

    92

说明/提示

Consider the first example. In this test, we don't really have any choice, so we need to add at least five progressions to make the first element equals 55. The array aa becomes [5,10,15][5, 10, 15].

Consider the second example. In this test, let's add one progression on the segment [1;3][1; 3] and two progressions on the segment [4;6][4; 6]. Then, the array aa becomes [1,2,3,2,4,6][1, 2, 3, 2, 4, 6].

考虑第一个例子。在该测试中,我们实际上没有任何选择,因此至少需要添加五个等差数列,使得第一个元素等于 55。此时数组 aa 变为 [5,10,15][5, 10, 15]。

考虑第二个例子。在该测试中,我们在区间 [1;3][1; 3] 上添加一个等差数列,在区间 [4;6][4; 6] 上添加两个等差数列。此时数组 aa 变为 [1,2,3,2,4,6][1, 2, 3, 2, 4, 6]。

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

首页