B-Queue on Bus Stop
来源:互联网 发布:网络延迟对网速的影响 编辑:程序博客网 时间:2024/05/21 17:06
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. Thei-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 andm(1 ≤ n, m ≤ 100). The next line containsn 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
4 32 3 2 1
3
3 41 2 1
1
#include <iostream>#include<algorithm>#include<cstdio>#include<cmath>#include<cstring>#include<cstdlib>using namespace std;int main(){ int n, m, i, x = 0, y = 0; int a[100]; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) { scanf("%d", &a[i]); } for (i = 0; i < n; i++) { x += a[i]; if (x == m) { x = 0; y++; } else if (x > m) { x = 0; y++; i--; } else if (i == n - 1 && x < m) y++; } printf("%d", y); return 0;}
- B-Queue on Bus Stop
- B-Queue on Bus Stop
- Queue on Bus Stop
- cf435A Queue on Bus Stop
- A. Queue on Bus Stop
- A. Queue on Bus Stop
- Queue on Bus Stop CodeForces
- Codeforces 435A Queue on Bus Stop
- Codeforces 435A Queue on Bus Stop
- Codeforces Round #249 (Div. 2) A. Queue on Bus Stop
- codeforces 435A Queue on Bus Stop(模拟水题)
- Codeforces Round #249 (Div. 2) A - Queue on Bus Stop
- CodeForces NO.435A Queue on Bus Stop(汽车载人)
- B. Seating On Bus
- B. Seating On Bus
- codeforces 660B. Seating On Bus
- Codeforces 660B Seating On Bus 【模拟】
- CodeForces 660 B. Seating On Bus【模拟】
- 平台中配置网格列表样式报:ORA-01461错误
- html js highcharts绘制圆饼图表
- RadioButton的特定使用场景
- java中判断字符串是否为数字的三种方法
- Spring 4.2.4.RELEASE MVC 学习笔记 - 4.1(咋个办呢 zgbn)
- B-Queue on Bus Stop
- 画流程图的工具
- 配置简单cas客户端
- Android Touch事件分发—拦截—处理
- Objective-C页面跳转方法总结
- 新手学习opencv六:kmeans聚类
- Android Studio 中的Android工程目录结构
- hdu 2819 Swap
- C- Expression