Timus 1787. Turn for MEGA 题解
生活随笔
收集整理的這篇文章主要介紹了
Timus 1787. Turn for MEGA 题解
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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
| 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 题解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 地震 matlab,MATLAB在地震信
- 下一篇: 音阶频率对照表_音符与频率关系对照表