F - Garbage Disposal

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 a_iai​ — 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 \le n \le 2\cdot10^5, 1 \le k \le 10^91≤n≤2⋅105,1≤k≤109) — number of days to consider and bag's capacity. The second line contains nn space separated integers a_iai​ (0 \le a_i \le 10^90≤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.

Sample 1

InputcopyOutputcopy
3 2
3 2 1
3

Sample 2

InputcopyOutputcopy
5 1
1000000000 1000000000 1000000000 1000000000 1000000000
5000000000

Sample 3

InputcopyOutputcopy
3 2
1 0 1
2

Sample 4

InputcopyOutputcopy
4 4
2 8 4 1
4

解法:每天都装x/y袋垃圾,剩余的x%y留到第二天(这样能尽量让每一袋装满),如果前一天剩下的和今天剩下的加起来小于y也要算作一袋

代码:

#include <iostream>
using namespace std;
#define ll long long
int main(){
    ll n,k;
    scanf("%lld%lld",&n,&k);
    ll yu=0;
    ll ans=0;
    for(ll i=1;i<=n;i++){
        ll temp;
        scanf("%lld",&temp);
        if(yu==0){
            yu=temp%k;
            ans=ans+temp/k;
        }else{
            if(yu+temp<=k){
                ans++;
                yu=0;
            }else{
                ans=ans+(temp+yu)/k;
                yu=(temp+yu)%k;
            }
        }
    }
    if(yu!=0)ans++;
    printf("%lld\n",ans);
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值