`
bcyy
  • 浏览: 1824306 次
文章分类
社区版块
存档分类
最新评论

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 thatkcars 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 startednminutes 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 integerskandn(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 integersa1, …,an(0 ≤ai≤ 100), whereaiis the number of cars that approached the turn during thei-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;
}



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics