CF1070D.Garbage Disposal

普及-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Enough is enough. Too many times it happened that Vasya forgot to dispose of garbage and his apartment stank afterwards. Now he wants to create a garbage disposal plan and stick to it.

For each of next nn days Vasya knows aia_i — number of units of garbage he will produce on the ii-th day. Each unit of garbage must be disposed of either on the day it was produced or on the next day. Vasya disposes of garbage by putting it inside a bag and dropping the bag into a garbage container. Each bag can contain up to kk units of garbage. It is allowed to compose and drop multiple bags into a garbage container in a single day.

Being economical, Vasya wants to use as few bags as possible. You are to compute the minimum number of bags Vasya needs to dispose of all of his garbage for the given nn days. No garbage should be left after the nn-th day.

够了!维佳已经太多次忘记处理垃圾,导致公寓随后臭气熏天。现在他想制定一个垃圾处理计划并严格遵守。

对于接下来的 nn 天中的每一天,维佳都知道第 ii 天将产生 aia_i 单位的垃圾。每单位垃圾必须在产生的当天或第二天内处理完毕。维佳通过将垃圾装入袋子,再将袋子投入垃圾箱来处理垃圾。每个袋子最多可容纳 kk 单位垃圾。允许在同一天内准备并投入多个袋子到垃圾箱中。

出于节约考虑,维佳希望使用尽可能少的袋子。你需要计算维佳在给定的 nn 天内处理全部垃圾所需的最少袋子数量。第 nn 天之后不得残留任何垃圾。

输入格式

The first line of the input contains two integers nn and kk (1≤n≤2⋅105,1≤k≤1091 \le n \le 2\cdot10^5, 1 \le k \le 10^9) — number of days to consider and bag's capacity. The second line contains nn space separated integers aia_i (0≤ai≤1090 \le a_i \le 10^9) — the number of units of garbage produced on the ii-th day.

输入的第一行包含两个整数 nn 和 kk(1≤n≤2⋅1051 \le n \le 2\cdot10^5,1≤k≤1091 \le k \le 10^9)—— 分别表示需考虑的天数和垃圾袋的容量。
第二行包含 nn 个用空格分隔的整数 aia_i(0≤ai≤1090 \le a_i \le 10^9)—— 表示第 ii 天产生的垃圾单位数量。

输出格式

Output a single integer — the minimum number of bags Vasya needs to dispose of all garbage. Each unit of garbage should be disposed on the day it was produced or on the next day. No garbage can be left after the nn-th day. In a day it is allowed to compose and drop multiple bags.

输出一个整数——Vasya 处理所有垃圾所需的最少袋子数量。每单位垃圾必须在产生的当天或第二天处理完毕,且不能有任何垃圾留到第 nn 天之后。每天可以制作并投放多个袋子。

输入输出样例

  • 输入#1

    3 2
    3 2 1

    输出#1

    3
  • 输入#2

    5 1
    1000000000 1000000000 1000000000 1000000000 1000000000

    输出#2

    5000000000
  • 输入#3

    3 2
    1 0 1

    输出#3

    2
  • 输入#4

    4 4
    2 8 4 1

    输出#4

    4

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

首页