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

注意:

1 每分钟只能通过k车了,如果不足k车,那么本分钟内也不会通过超过k车了

#include <iostream>
using namespace std;void TurnForMEGA()
{int k = 0, n = 0, a = 0, left = 0;cin>>k>>n;   for (int i = 0; i < n; i++){cin>>a;left = a + left - k;if (left < 0) left = 0;}cout<<left<<endl;
}

Timus 1787. Turn for MEGA 题解相关推荐

  1. BZOJ 1787 [Ahoi2008]Meet紧急集合 题解与分析

    [Ahoi2008]Meet 紧急集合 Time Limit: 20 Sec   Memory Limit: 162 MB Description Input Output Sample Input ...

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

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

  3. SCU 4445 Right turn(dfs)题解

    思路:离散化之后,直接模拟就行,标记vis开三维 代码: #include<iostream> #include<algorithm> #include<cstdio&g ...

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

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

  5. 2017 ACM ICPC Asia Shenyang Regional Contest 题解(10 / 13)【每日亿题2 / 16】

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A.(2017 ICPC shenyang I)Little Boxes B.(2017 ICP ...

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

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

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

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

  8. 1787: [Ahoi2008]Meet 紧急集合

    1787: [Ahoi2008]Meet 紧急集合 Time Limit: 20 Sec  Memory Limit: 162 MB Submit: 1482  Solved: 652 [Submit ...

  9. hdu 2438 Turn the corner [ 三分 ]

    传送门 Turn the corner Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  10. 【NOIP2018】旅行 (洛谷P5049 / P5022) O(nlogn)题解

    阅读和学习本篇题解前,你应该掌握: C++ STL stack.vector.queue.pair的基本用法: 递归.搜索和贪心思想. 洛谷传送门 P5049 此题可以先从数据范围入手,观察m的范围( ...

最新文章

  1. Kaggle 首战拿银总结 | 入门指导 (长文、干货)
  2. windows10自动填充密码开机自动登陆
  3. input onclick点击button无反应_热图分析:精确洞察用户点击偏好
  4. 语言省考安徽考区_安徽省中小学新任教师公开招聘统一笔试 中学信息技术学科考试大纲...
  5. java 多态_Java面向对象 —— 多态
  6. 修正《用Docker快速搭建Go开发环境》文章中的一处错误
  7. git bash here创建项目无法选择m_版本控制Git基础及使用详解
  8. 软件实施提升效率的五个工具
  9. pppoe拨号中的server name和service name
  10. spingboot视图层实例(JSP+Freemaker)以及自定义配置读取
  11. Hive中Join的 MR 底层原理
  12. 【NIPS 2020】通过文本压缩,让BERT支持长文本
  13. [L4D]目录Missions中任务与地图关系
  14. Telink TLSR9213 使用JTag方式不能正确连接,烧写失败的问题
  15. Field属性(域)
  16. 如果在魔兽世界中,做一个合格野性德
  17. 在html中进行表单设计,谈谈网页中的表单设计
  18. android 渐变的背景色,Android背景渐变xml
  19. 一步步推导由欧拉角到旋转矩阵的计算过程
  20. python虚假评论识别程序_还在刷虚假评论?小心了,可以检测虚假评论的第三方工具来了...

热门文章

  1. Iptables 指南 1.1.19
  2. TeamViewer 远程连接一直显示正在初始化显示参数的解决方案
  3. 软考高项3门45分总结及分享
  4. 原生WebView长截图 和 Tencent x5webview截长图
  5. Redfish Data model (红鱼的资料模型)
  6. 刷重庆高校网课的方法
  7. 苹果ppt_苹果又开发布会了,这几个PPT设计技巧值得学习
  8. java坦克大战爆炸效果_Java坦克大战 (五) 之产生敌方坦克和爆炸效果
  9. MYSQL查询语句大全集锦
  10. 景观干扰度(arcgis和fragstats)