A. Queue on Bus Stop
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups.

The bus stop queue has n groups of people. The i-th group from the beginning has ai people. Every 30 minutes an empty bus arrives at the bus stop, it can carry at most m people. Naturally, the people from the first group enter the bus first. Then go the people from the second group and so on. Note that the order of groups in the queue never changes. Moreover, if some group cannot fit all of its members into the current bus, it waits for the next bus together with other groups standing after it in the queue.

Your task is to determine how many buses is needed to transport all n groups to the dacha countryside.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 100). The next line contains n integers: a1, a2, ..., an (1 ≤ ai ≤ m).

Output

Print a single integer — the number of buses that is needed to transport all n groups to the dacha countryside.

Sample test(s)
input
4 3
2 3 2 1
output
3
input
3 4
1 2 1
output
1
模拟题……没啥好说的。贴代码:
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
#define inf 0x7fffffff
#define LL long long
#define read fastreading()
inline int fastreading()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int a[1000];
int n,m,ans,s;
int main()
{
n=read;
m=read;
for (int i=1;i<=n;i++)
{a[i]=read;if (a[i]+s<=m) {s+=a[i];}else {ans++;s=a[i];}if (a[i]==m){ans++;s=0;}}
if (s) ans++;
cout<<ans;
}

最新文章

  1. iOS 滑动性能优化
  2. PhoneGap中navigator.notification.confirm的用法详解
  3. (String) 205.Isomorphic Strings
  4. 黄聪:Wordpress、PHP使用POST数据过大导致MySQL server has gone away报错原因分析
  5. Hadoop发展历史简介
  6. HDU 4288 Coder(线段树)
  7. 浅谈 trie树 及其实现
  8. 在Word中直接用快捷键查找选中文本
  9. C++ template学习一(函数模板和模板函数)
  10. 《Windows驱动开发技术详解》之自定义StartIO
  11. Django+xadmin打造在线教育平台(八)
  12. bzoj 1558: [JSOI2009]等差数列
  13. 美团技术沙龙01 - 58到家服务的订单调度&amp;数据分析技术
  14. Actor消息发送及等待结果关键字
  15. 关于动态内存malloc和realloc
  16. hihocoder #1828 : Saving Tang Monk II(BFS)
  17. 基于 HTML5 Canvas 的 3D WebGL 机房创建
  18. windows Maven3.0 服务器配置搭建
  19. python实例:元组命名 频次统计 字典排序
  20. 05-oralce转换函数

热门文章

  1. android style 退出动画 解决退出动画无效问题
  2. Com编程入门——什么是COM,如何使用COM
  3. [AngularJS] Using $parse Service
  4. [Redux] Reducer Composition with Arrays
  5. iTerm2和oh-my-zsh的个性化定制
  6. NYOJ-571 整数划分(三)
  7. ListControl一细节处理
  8. codevs 2449 骑士精神 (IDDfs)
  9. C# 面向对象 , 继承
  10. ASP.NET数据绑定控件简介