A15059 | Progressions Covering
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given two arrays: an array $a$ consisting of $n$ zeros and an array $b$ consisting of $n$ integers.
You can apply the following operation to the array $a$ an arbitrary number of times: choose some subsegment of $a$ of length $k$ and add the arithmetic progression $1, 2, \ldots, k$ to this subsegment — i. e. add $1$ to the first element of the subsegment, $2$ to the second element, and so on. The chosen subsegment should be inside the borders of the array $a$ (i.e., if the left border of the chosen subsegment is $l$ , then the condition $1 \le l \le l + k - 1 \le n$ should be satisfied). Note that the progression added is always $1, 2, \ldots, k$ but not the $k, k - 1, \ldots, 1$ or anything else (i.e., the leftmost element of the subsegment always increases by $1$ , the second element always increases by $2$ and so on).
Your task is to find the minimum possible number of operations required to satisfy the condition $a_i \ge b_i$ for each $i$ from $1$ to $n$ . Note that the condition $a_i \ge b_i$ should be satisfied for all elements at once.
You can apply the following operation to the array $a$ an arbitrary number of times: choose some subsegment of $a$ of length $k$ and add the arithmetic progression $1, 2, \ldots, k$ to this subsegment — i. e. add $1$ to the first element of the subsegment, $2$ to the second element, and so on. The chosen subsegment should be inside the borders of the array $a$ (i.e., if the left border of the chosen subsegment is $l$ , then the condition $1 \le l \le l + k - 1 \le n$ should be satisfied). Note that the progression added is always $1, 2, \ldots, k$ but not the $k, k - 1, \ldots, 1$ or anything else (i.e., the leftmost element of the subsegment always increases by $1$ , the second element always increases by $2$ and so on).
Your task is to find the minimum possible number of operations required to satisfy the condition $a_i \ge b_i$ for each $i$ from $1$ to $n$ . Note that the condition $a_i \ge b_i$ should be satisfied for all elements at once.
输入格式
The first line of the input contains two integers $n$ and $k$ ( $1 \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 $n$ integers $b_1, b_2, \ldots, b_n$ ( $1 \le b_i \le 10^{12}$ ), where $b_i$ is the $i$ -th element of the array $b$ .
The second line of the input contains $n$ integers $b_1, b_2, \ldots, b_n$ ( $1 \le b_i \le 10^{12}$ ), where $b_i$ is the $i$ -th element of the array $b$ .
输出格式
Print one integer — the minimum possible number of operations required to satisfy the condition $a_i \ge b_i$ for each $i$ from $1$ to $n$ .
输入输出样例
输入 #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 $5$ . The array $a$ becomes $[5, 10, 15]$ .
Consider the second example. In this test, let's add one progression on the segment $[1; 3]$ and two progressions on the segment $[4; 6]$ . Then, the array $a$ becomes $[1, 2, 3, 2, 4, 6]$ .
Consider the second example. In this test, let's add one progression on the segment $[1; 3]$ and two progressions on the segment $[4; 6]$ . Then, the array $a$ becomes $[1, 2, 3, 2, 4, 6]$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted