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 ≤ kn ≤ 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相关推荐

  1. java 合并和拆分单元格_如何轻松合并和拆分电子书

    java 合并和拆分单元格 Whether you want to merge collections of short stories into a DIY anthology, or you wa ...

  2. 英语单词 voltage simulation synthesize junction asynchronous mega optimize

    voltage 英 [ˈvəʊltɪdʒ]美 [ˈvoʊltɪdʒ] n. 电压;伏特数 [例句] The output voltage rises, compensating for the ori ...

  3. HDU 4869 Turn the pokers(思维+组合公式+高速幂)

    Turn the pokers 大意:给出n次操作,给出m个扑克.然后给出n个操作的个数a[i],每一个a[i]代表能够翻的扑克的个数,求最后可能出现的扑克的组合情况. Hint Sample Inp ...

  4. 11/1787, 哈工大小学妹的比赛上分经验,附战友招募

    ↑↑↑关注后"星标"Datawhale 每日干货 & 每月组队学习,不错过 Datawhale干货 作者:刘钰舒,哈尔滨工业大学研一 我是来自HIT的刘钰舒,因为我也是新手 ...

  5. R语言禁止数值表示为科学计数法实战(Turn Off Scientific Notation ):全局设置或者单变量设置

    R语言禁止数值表示为科学计数法实战(Turn Off Scientific Notation ):全局设置或者单变量设置 目录

  6. Ural 1018 (树形DP+背包+优化)

    题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17662 题目大意:树枝上间连接着一坨坨苹果(不要在意'坨'),给 ...

  7. Turn over a new leaf

    Turn over a new leaf 重新开始 I finally turned over a new leaf and got into the good habit of arriving a ...

  8. bzoj1814 Ural 1519 Formula 1(插头dp模板题)

    1814: Ural 1519 Formula 1 Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 924  Solved: 351 [Submit][S ...

  9. mega_[MEGA DEAL] Android课程的Java基础知识(61%折扣)

    mega 与大学教授一起掌握Android应用背后的语言! 嘿,怪胎, 本周,在我们的JCG Deals商店中,我们提供了一个极端的报价. 我们提供的Java Essentials for Andro ...

  10. mega_[MEGA DEAL]带有Kotlin捆绑包的完整Android Oreo(95%折扣)

    mega 使用Android最快的编程语言之一进行105小时的培训,深入了解黄铜技术 嘿,怪胎, 本周,在我们的JCG Deals商店中,我们提供了另一个超值优惠. 我们提供带有Kotlin Bund ...

最新文章

  1. Elasticsearch 常见的 8 种错误及最佳实践
  2. 计算机三级交换机允许中继配置,计算机三级交换机配置命令总结
  3. 软件项目经理职责[转](
  4. C#switch语句简单测试
  5. 老刘说NLP:焦虑被大肆贩卖下的自然语言处理学习思考
  6. 《Ext JS权威指南》——1.2节JSON概述
  7. 如何高效检查一个数组中是否包含某个值?
  8. node --进行后台的环境搭建
  9. 2021陆川高考成绩查询,陆川中考成绩查询2021
  10. tensorflow之random_normal
  11. The field file exceeds its maximum permitted size of 1048576 bytes
  12. jquery实现60秒倒计时
  13. 诀窍|Callnovo助中国电动自行车成为大洋彼岸街头美丽风景线
  14. e430c更换光盘托架_如何处理PC上未使用的光盘驱动器托架
  15. SAP FICO 财务成本知识库
  16. 全国海选第四期:北京和海外赛区(视频)
  17. nginx配置不生效
  18. 循序渐进实现仿QQ界面(三):界面调色与控件自绘
  19. 计算机辅助物理化学实验 唐典勇课后答案,计算机辅助物理化学实验(第2版)...
  20. java表白 520

热门文章

  1. UG软件制图的几个重要技巧,你知道吗?
  2. 【OpenCV】用sobel算子和Susan算子提取恩智浦智能车赛道边缘
  3. WinRAR无广告版下载方式
  4. java pkcs8_java中公钥,私钥,pkcs1格式,pkcs8格式互转
  5. python 人脸打卡系统
  6. fh 幅频特性曲线怎么画fl_测量rc带通滤波器的幅频特性和相频特性-电子科技大学.ppt...
  7. 九九乘法表的简单代码
  8. py将dicm格式图片转为jpg格式
  9. 5G NR标准协议架构-5G协议应该怎么看?
  10. python利用pyhive 连接hive