Server
Description
You are in charge of a server that needs to run some submitted tasks on a first-come, first-served basis. Each day, you can dedicate the server to run these tasks for at most T minutes. Given the time each task
takes, you want to know how many of them will be finished today.
Consider the following example. Assume T = 180 and the tasks take 45, 30, 55, 20, 80, and 20 minutes (in order they are submitted). Then, only four tasks can be completed. The first four tasks can be completed because they take 150 minutes, but not the first
five, because they take 230 minutes which is greater than 180. Notice that although there is enough time to perform the sixth task (which takes 20 minutes) after completing the fourth task, you cannot do that because the fifth task is not done yet.
Input
The input consists of a single test case. The first line contains two integers n and T where 1≤ n ≤50 is the number of tasks and 1 ≤ T ≤500. The next line contains n positive integers no more than 100 indicating how long each task takes in order they are submitted.
Output
Display the number of tasks that can be completed in T minutes on a first-come, first-served basis.
Sample Input
6 180 45 30 55 20 80 20
Sample Output
4
在不超过时间T的情况下,能够有几个人完成买票
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
int n,t,a,ans=0;
long long sum=0;
scanf("%d %d",&n,&t);
for(int i=0;i<n;i++)
{
scanf("%d",&a);
sum=sum+a;
if(sum<=t)
ans++;
}
printf("%d\n",ans);
return 0;
}
上一篇: 花粉怎么吃,有些什么功效
下一篇: 读取注册表
推荐阅读
-
Windows server 2008 r2下MySQL5.7.17 winx64安装版配置方法图文教程
-
Ubuntu Server 16.04下mysql8.0安装配置图文教程
-
phpstudy教程之自带ftp server使用方法详解(图文)
-
MySQL Community Server安装失败怎么办 MySQL Community Server正确安装方法
-
sql server通过脚本进行数据库压缩全备份的方法【推荐】
-
在SQL Server中使用命令调用SSIS包的具体方法
-
完美解决SQL server2005中插入汉字变成问号的问题
-
SQL Server常用存储过程及示例
-
浅析Sql server锁,独占锁,共享锁,更新锁,乐观锁,悲观锁
-
SQL Server 比较日期大小的方法