Queue on Bus Stop
2016-01-04 13:13
585 查看
Description
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 Input
Input
Output
Input
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 Input
Input
4 3 2 3 2 1
Output
3
Input
3 4 1 2 1
Output
1
#include<cstdio> #include<iostream> using namespace std; int a[105]; int main(){ int n,m,i,ans,now; while(cin>>n>>m){ for(i=0;i<n;i++){ cin>>a[i]; } ans=1; now=m; for(i=0;i<n;){ if(a[i]<=now){ now-=a[i]; i++; } else{ now=m; ans++; } } cout<<ans<<endl; } return 0; }
相关文章推荐
- UINavigationController以及UITabBarController背景图片和文字的设置
- easyui 日期控件清空值
- 王立平-- ContentValues , HashTable , HashMap差别
- UIView
- iOS UIScrollView的属性
- Invalid result location value/parameter 解决办法
- Android开发学习之路-使用Handler和Message更新UI
- Ext Combobox 显示valueField值 不显示displayField问题
- iOS UI-表格控制器(UITableView)-基本使用
- iOS中UITableView性能优化
- 在UITableView或UICollectionView的自定义的cell里添加手势或button,响应方法时如何传参数
- iOS 中一个带尖角并且尖角指向固定点的UILabel
- 连接数据库超时设置autoReconnect=true
- UITabBarController使用
- 让ThreadPoolExecutor的workQueue占满时自动阻塞submit()方法
- Build Action
- UITextField 光标的缩进问题
- getContextPath、getServletPath、getRequestURI的区别
- arm交叉编译器gnueabi、none-eabi、arm-eabi、gnueabihf、gnueabi区别
- iOS 9中UIDynamics实现真正的圆形碰撞