前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >2018-2019 ICPC, NEERC, Southern Subregional Contest D. Garbage Disposal

2018-2019 ICPC, NEERC, Southern Subregional Contest D. Garbage Disposal

作者头像
glm233
发布2020-09-28 10:44:59
3070
发布2020-09-28 10:44:59
举报
文章被收录于专栏:glm的全栈学习之路

D. Garbage Disposal

time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 aiai — 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.

Input

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

Output

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.

Examples

input

Copy

代码语言:javascript
复制
3 2
3 2 1

output

Copy

代码语言:javascript
复制
3

input

Copy

代码语言:javascript
复制
5 1
1000000000 1000000000 1000000000 1000000000 1000000000

output

Copy

代码语言:javascript
复制
5000000000

input

Copy

代码语言:javascript
复制
3 2
1 0 1

output

Copy

代码语言:javascript
复制
2

input

Copy

代码语言:javascript
复制
4 4
2 8 4 1

output

Copy

代码语言:javascript
复制
4



题意:倒垃圾,a[i]表示垃圾数目,必须每一个垃圾必须要用容量为k的垃圾袋装,i表示第i天,当天的垃圾最多只能留到第二天,求最少花费的垃圾袋数

思路:贪心,对于每一个垃圾袋而言,要尽量的装满,当天的垃圾能装满一个袋子就马上装好,剩下a[i]%k个垃圾可以第二天和第二天的垃圾一起装

代码语言:javascript
复制
// luogu-judger-enable-o2
#include<bits/stdc++.h>
#include<unordered_set>
#define rg register ll
#define inf 2147483647
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define ll long long
#define maxn 300005
const double eps = 1e-6;
using namespace std;
inline ll read()
{
	char ch = getchar(); ll s = 0, w = 1;
	while (ch < 48 || ch>57) { if (ch == '-')w = -1; ch = getchar(); }
	while (ch >= 48 && ch <= 57) { s = (s << 1) + (s << 3) + (ch ^ 48); ch = getchar(); }
	return s * w;
}
inline void write(ll x)
{
	if (x < 0)putchar('-'), x = -x;
	if (x > 9)write(x / 10);
	putchar(x % 10 + 48);
}
ll n,k,a[maxn];
int main()
{
    cin>>n>>k;
    for(rg i=1;i<=n;i++)a[i]=read();
    ll sum=0,temp=inf;
    for(rg i=1;i<=n;i++)
    {
        if(temp<=k&&temp)
        {
            sum++;
            a[i]-=k-temp;
            if(a[i]<0)a[i]=0;
        }
        if(a[i]>=0)
        {
        sum+=a[i]/k;
        temp=a[i]%k;
        }
        //cout<<temp<<" "<<sum<<" "<<a[i]<<endl;
    }
    cout<<sum+(temp!=0)<<endl;
   	return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/09/10 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档