Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
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
37000
代码可运行
举报
运行总次数:0
代码可运行

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
代码运行次数:0
运行
AI代码解释
复制
3 2
3 2 1

output

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
3

input

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
5 1
1000000000 1000000000 1000000000 1000000000 1000000000

output

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
5000000000

input

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
3 2
1 0 1

output

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
2

input

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
4 4
2 8 4 1

output

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
4



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

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

代码语言:javascript
代码运行次数:0
运行
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
5070
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
6320
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
4060
Codeforces Round #605 (Div. 3) D. Remove One Element
You are given an array aa consisting of nn integers.
glm233
2020/09/28
5030
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
3330
Codeforces Round #633 (Div. 2)D Edge Weight Assignment(构造、树的权值异或)
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
4020
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
4790
Codeforces Round #624 (Div. 3) C - Perform the Combo
You want to perform the combo on your opponent in one popular fighting game. The combo is the string ss consisting of nn lowercase Latin letters. To perform the combo, you have to press all buttons in the order they appear in ss. I.e. if s=s="abca" then you have to press 'a', then 'b', 'c' and 'a' again.
glm233
2020/09/28
6760
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
4440
模拟赛 2018 Benelux Algorithm Programming Contest (BAPC 18)(部分题)
After the festive opening of your new store, the Boutique store for Alternative Paramedicine and Cwakhsahlvereigh, to your disappointment you find out that you are not mak- ing as many sales as you had hoped. To remedy this, you decide to run a special offer: you will mark some subset of the n items for sale in your store as participating in the offer, and if people buy exactly two of these items, and the cost of these items is strictly more than X euros, you will give them a free complimentary unicorn horn! Since you recently found out all your unicorn horns are really narwahl tusks, you decide to rig the offer by picking the participating items in such a way that no one can earn a horn anyway. To make sure no one becomes suspicious, you want to mark as many items as possible as participating in the offer. Input • On the first line two integers, 1 ≤ n ≤ 10 5 , the number of items for sale in your store, and 1 ≤ X ≤ 10 9 , the minimum cost specified in the statement. • On the second line n positive integers, each at most 10 9 . These are the prices of the items in the store. Output Print the maximum number of items you can mark as part of your special offer, without anyone actually being able to receive a horn. Sample Input 1 Sample Output 1 5 6 1 2 3 4 5 3 Sample Input 2 Sample Output 2 5 10 4 8 1 9 7 2 Sample Input 3 Sample Output 3 4 10 1 3 1 7 4 4 Problem A: A Prize No One Can Win Sample Input 4 Sample Output 4 1 5 6 1
glm233
2020/09/28
4400
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
3360
Codeforces Beta Round #72 (Div. 1 Only)B. Doctor
There are n animals in the queue to Dr. Dolittle. When an animal comes into the office, the doctor examines him, gives prescriptions, appoints tests and may appoint extra examination. Doc knows all the forest animals perfectly well and therefore knows exactly that the animal number i in the queue will have to visit his office exactly ai times. We will assume that an examination takes much more time than making tests and other extra procedures, and therefore we will assume that once an animal leaves the room, it immediately gets to the end of the queue to the doctor. Of course, if the animal has visited the doctor as many times as necessary, then it doesn't have to stand at the end of the queue and it immediately goes home.
glm233
2020/09/28
3630
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
5130
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
2900
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
2880
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
4040
AIM Tech Round 5 (rated, Div. 1 + Div. 2)C. Rectangles
You are given nn rectangles on a plane with coordinates of their bottom left and upper right points. Some (n−1)(n−1) of the given nn rectangles have some common point. A point belongs to a rectangle if this point is strictly inside the rectangle or belongs to its boundary.
glm233
2020/09/28
3180
AIM Tech Round 5 (rated, Div. 1 + Div. 2)C. Rectangles
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
3710
Codeforces Round #615 (Div. 3)C. Product of Three Numbers
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
5210
Codeforces Round #615 (Div. 3)B. Collecting Packages
There is a robot in a warehouse and nn packages he wants to collect. The warehouse can be represented as a coordinate grid. Initially, the robot stays at the point (0,0)(0,0). The ii-th package is at the point (xi,yi)(xi,yi). It is guaranteed that there are no two packages at the same point. It is also guaranteed that the point (0,0)(0,0) doesn't contain a package.
glm233
2020/09/28
6830
Codeforces Round #615 (Div. 3)B. Collecting Packages
推荐阅读
相关推荐
Codeforces Round #627 (Div. 3) E. Sleeping Schedule (DP)
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验