首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >2018-2019 ICPC, NEERC, Southern Subregional Contest D. Garbage Disposal

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

作者头像
glm233
发布于 2020-09-28 02:44:59
发布于 2020-09-28 02:44:59
3950
举报

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
AI代码解释
复制
3 2
3 2 1

output

Copy

代码语言:javascript
AI代码解释
复制
3

input

Copy

代码语言:javascript
AI代码解释
复制
5 1
1000000000 1000000000 1000000000 1000000000 1000000000

output

Copy

代码语言:javascript
AI代码解释
复制
5000000000

input

Copy

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

output

Copy

代码语言:javascript
AI代码解释
复制
2

input

Copy

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

output

Copy

代码语言:javascript
AI代码解释
复制
4



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

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

代码语言:javascript
AI代码解释
复制
// 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 删除。

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

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
Codeforces Round #627 (Div. 3) E. Sleeping Schedule (DP)
Vova had a pretty weird sleeping schedule. There are hh hours in a day. Vova will sleep exactly nn times. The ii-th time he will sleep exactly after aiai hours from the time he woke up. You can assume that Vova woke up exactly at the beginning of this story (the initial time is 00). Each time Vova sleeps exactly one day (in other words, hh hours).
glm233
2020/09/28
5320
Codeforces Round #605 (Div. 3) D. Remove One Element
You are given an array aa consisting of nn integers.
glm233
2020/09/28
5380
2019.8.15乘兴打Codeforces Round #569 (Div. 2)小记
Recently, on the course of algorithms and data structures, Valeriy learned how to use a deque. He built a deque filled with nn elements. The ii-th element is aiai (ii = 1,2,…,n1,2,…,n). He gradually takes the first two leftmost elements from the deque (let's call them AA and BB, respectively), and then does the following: if A>BA>B, he writes AA to the beginning and writes BB to the end of the deque, otherwise, he writes to the beginning BB, and AA writes to the end of the deque. We call this sequence of actions an operation.
glm233
2020/09/28
6540
Codeforces Round #547 (Div. 3)D. Colored Boots
D. Colored Boots time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are nn left boots and nn right boots. Each boot has a color which is denoted as a lowercase Latin letter or a question mark
glm233
2020/09/28
4420
Codeforces Round #629 (Div. 3) F. Make k Equal (技巧暴力,类前缀和,思维,数学)
You are given the array aa consisting of nn elements and the integer k≤nk≤n.
glm233
2020/09/28
5090
Codeforces Round #613 (Div. 2)B. Just Eat It!
Today, Yasser and Adel are at the shop buying cupcakes. There are nn cupcake types, arranged from 11 to nn on the shelf, and there are infinitely many of each type. The tastiness of a cupcake of type ii is an integer aiai. There are both tasty and nasty cupcakes, so the tastiness can be positive, zero or negative.
glm233
2020/09/28
4710
Codeforces Round #547 (Div. 3)E. Superhero Battle
A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly nn minutes. After a round ends, the next round starts immediately. This is repeated over and over again.
glm233
2020/09/28
4320
Codeforces Round #547 (Div. 3)F1. Same Sum Blocks (Easy)
This problem is given in two editions, which differ exclusively in the constraints on the number nn.
glm233
2020/09/28
3080
Codeforces Round #633 (Div. 2)D Edge Weight Assignment(构造、树的权值异或)
You have unweighted tree of nn vertices. You have to assign a positive weight to each edge so that the following condition would hold:
glm233
2020/09/28
3550
Codeforces Round #633 (Div. 2)D Edge Weight Assignment(构造、树的权值异或)
Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) B. Bash's Big Day (Hash+简单数论)
Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases.
glm233
2020/09/28
5030
CF思维联系– CodeForces - 991C Candies(二分)
After passing a test, Vasya got himself a box of n candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself.
风骨散人Chiam
2020/10/28
5720
Codeforces Round #502 (in memory of Leopoldo Taravilse, Div. 1 + Div. 2)C. The Phone Number
Mrs. Smith is trying to contact her husband, John Smith, but she forgot the secret phone number!
glm233
2020/09/28
3640
Codeforces Round #547 (Div. 3)F2. Same Sum Blocks (Hard)
This problem is given in two editions, which differ exclusively in the constraints on the number nn.
glm233
2020/09/28
4290
Codeforces Round #382 (Div. 2) D. Taxes (数论 哥猜 大胆尝试)
Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to n (n ≥ 2) burles and the amount of tax he has to pay is calculated as the maximum divisor of n (not equal to n, of course). For example, if n = 6 then Funt has to pay 3 burles, while for n = 25 he needs to pay 5 and if n = 2 he pays only 1 burle.
glm233
2020/09/28
3180
Codeforces Round #547 (Div. 3)G. Privatization of Roads in Treeland
Treeland consists of n cities and n−1 roads. Each road is bidirectional and connects two distinct cities. From any city you can get to any other city by roads. Yes, you are right — the country's topology is an undirected tree.
glm233
2020/09/28
4000
Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round) C. Remove Adjacent
You are given a string ss consisting of lowercase Latin letters. Let the length of ss be |s||s|. You may perform several operations on this string.
glm233
2020/09/28
5620
Codeforces Round #547 (Div. 3)C. Polycarp Restores Permutation
An array of integers p1,p2,…,pnp1,p2,…,pn is called a permutation if it contains each number from 11 to nn exactly once. For example, the following arrays are permutations: [3,1,2][3,1,2], [1][1], [1,2,3,4,5][1,2,3,4,5] and [4,3,1,2][4,3,1,2]. The following arrays are not permutations: [2][2], [1,1][1,1], [2,3,4][2,3,4].
glm233
2020/09/28
5380
Codeforces Round #559 (Div. 2)B. Expansion coefficient of the array
Let's call an array of non-negative integers a1,a2,…,ana1,a2,…,an a kk-extension for some non-negative integer kk if for all possible pairs of indices 1≤i,j≤n1≤i,j≤n the inequality k⋅|i−j|≤min(ai,aj)k⋅|i−j|≤min(ai,aj) is satisfied. The expansion coefficient of the array aa is the maximal integer kk such that the array aa is a kk-extension. Any array is a 0-expansion, so the expansion coefficient always exists.
glm233
2020/09/28
6510
Codeforces Round #615 (Div. 3)C. Product of Three Numbers
You are given one integer number nn. Find three distinct integers a,b,ca,b,c such that 2≤a,b,c2≤a,b,c and a⋅b⋅c=na⋅b⋅c=n or say that it is impossible to do it.
glm233
2020/09/28
4040
Codeforces Round #615 (Div. 3)C. Product of Three Numbers
Codeforces 727D-T-shirts Distribution (字符串 贪心)
The organizers of a programming contest have decided to present t-shirts to participants. There are six different t-shirts sizes in this problem: S, M, L, XL, XXL, XXXL (sizes are listed in increasing order). The t-shirts are already prepared. For each size from S to XXXL you are given the number of t-shirts of this size.
glm233
2020/09/28
6800
推荐阅读
相关推荐
Codeforces Round #627 (Div. 3) E. Sleeping Schedule (DP)
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档