欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

URAL 1787. Turn for MEGA

发布时间:2024/8/1 编程问答 50 豆豆
生活随笔 收集整理的这篇文章主要介绍了 URAL 1787. Turn for MEGA 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

1787. Turn for MEGA

Time limit: 1.0 second
Memory limit: 64 MB
A traffic light at the turn for the “MEGA” shopping center from the Novomoskovskiy highway works in such a way that k cars are able to take a turn in one minute. At weekends all the residents of the city drive to the mall to take a shopping, which results in a huge traffic jam at the turn. Administration of the mall ordered to install a camera at the nearby bridge, which is able to calculate the number of cars approaching this turn from the city. The observation started n minutes ago. You should use the data from the camera to determine the number of cars currently standing in the traffic jam.

Input

The first line contains integers k and n (1 ≤ k, n ≤ 100), which are the number of cars that can take a turn to “MEGA” in one minute and the number of minutes passed from the beginning of observation. The second line contains space-separated integers a1, …, an (0 ≤ ai ≤ 100), where aiis the number of cars that approached the turn during the i-th minute. The observation started at morning, when there were no cars at the turn.

Output

Output the number of cars currently standing in the traffic jam.

Samples

input output
5 3 6 7 2 0
5 3 20 0 0 5


题的大概意思就是在一个路口,每分钟可以有k辆车转头,n分钟内分别有ai辆车通过,输出有多少车滞留。
刚开始想的太简单了,直接用了个sum把ai全加起来和k*n比较,后来发现下一分钟接近路口的车不能出现在上一分钟里。
#include<cstdio> #include<iostream> using namespace std; int main() {int k,n,sum;int a[1001];while(cin>>k>>n){sum=0;for(int i=0;i<n;i++){cin>>a[i];if(sum+a[i]>k)sum+=a[i]-k;elsesum=0;}cout<<sum<<endl;}return 0; }

总结

以上是生活随笔为你收集整理的URAL 1787. Turn for MEGA的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。