A. Queue on Bus Stop
来源:互联网 发布:淘宝订单物流查询 编辑:程序博客网 时间:2024/05/23 00:04
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.
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).
Print a single integer — the number of buses that is needed to transport all n groups to the dacha countryside.
#include<iostream>#include <stdio.h>
#define maxn 105
using namespace std;
int main()
{
int num[maxn] = {0};
int n,m;
int sum = 0;
int ans = 0;
scanf("%d %d",&n, &m);
for( int i = 0; i<n ;i++)
{
scanf("%d",&num[i]);
if(sum + num[i] > m)
{
sum = num[i];
ans++;
}
else
sum += num[i];
}
if( sum > 0)
ans ++;
printf("%d\n",ans);
}
- A. Queue on Bus Stop
- A. Queue on Bus Stop
- Codeforces 435A Queue on Bus Stop
- Codeforces 435A Queue on Bus Stop
- Queue on Bus Stop
- cf435A Queue on Bus Stop
- B-Queue on Bus Stop
- B-Queue on Bus Stop
- Queue on Bus Stop CodeForces
- 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(汽车载人)
- On a bus
- Dell服务器"A bus fatal error was detected on a component at bus 0 device 9 function 0"的解决方案
- B. Seating On Bus
- B. Seating On Bus
- Seating On Bus
- Mysql复制表结构、表数据
- 全栈工程师就是一棵歪脖子树
- MFC线程创建以及利用线程显示字符
- 黑马程序员 Java中根据YYYY-MM-DD格式的日期计算为星期几的两种实现方式
- POJ2186 Popular Cows 【裸缩环+Gabow算法强连通分量分解再建图】
- A. Queue on Bus Stop
- JDK1.5版本以后出现的新特性
- Android:用Handler实现异步处理功能
- spring bean作用域
- 求解:JQueryValidationEngine不支持双验证
- UI引擎开发系列(二) 事件分发处理
- 第一讲:数据库系统
- 护盾的实现
- 带个团队压力大应该如何做