Algorithm


Problem Name: 2 AD-HOC - beecrowd | 1793

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1793

Escalator

 

By Cristhian Bonilha, UTFPR BR Brazil

Timelimit: 1

Escalators have facilitated people’s lives a lot. Climbing stairs is one of the most boring tasks ever invented (after the invention of the stairs on the first place).

After a few observations, you realized that there is a lot of energy being spent with escalators, because they continue to work even when there is nobody using it. To avoid that, the owner of a local shopping mall installed a sensor that verifies when there is someone on the escalator. When the sensor detects no presence, the escalator is deactivated, this way saving energy until the next person arrives.

To be more precise, the system works on the following way: the escalator is initially inactive. The amount of time that a person takes to go from the beginning to the end of the escalator is 10 seconds. In other words, if one person arrives to the escalator on time t, the escalator will be active on times t, t+1, t+2, …, t+8 and t+9, and then will be deactivated on time t+10, when the person leaves the escalator. Such time window may be prolonged if one or more people arrive to the escalator during such process.

The owner of the local shopping mall now asked for your help. Write an algorithm that, given the times at which some people arrived at the escalator, tell for how many seconds the escalator was active.

 

Input

 

There will be at most 30 test cases. Each test case starts with a line containing one integer N, representing the number of people that used the escalator on that day (1 ≤ N ≤ 100).

On the next line, there will be N distinct integers, given in ascending order, representing the time t at which each person arrived at the escalator (1 ≤ t ≤ 1000).

The last test case is indicated when N = 0, which should not be processed.

 

Output

 

For each test case print one line, containing one integer, representing how many seconds the escalator was active.

 

 

 

Input Sample Output Sample

1
5
2
12 25
2
13 16
5
15 20 29 31 50
0

10
20
13
36

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming


#include <bits/stdc++.h>


using namespace std;

int main()
{
	int n;
	int v[105];
	
	while (1)
	{
		cin >> n;
		if (!n) return 0;
		
		int ans = 10;
		
		for (int i = 0 ; i  <  n ; i++)
		{
			cin >> v[i];
		}
		
		for (int i = 1; i  <  n; i++)
		{
			ans += min(10, v[i] - v[i - 1]);
		}
		cout << ans << '\n';
	}
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
1
5
2
12 25
2
13 16
5
15 20 29 31 50
0

Output

x
+
cmd
10
20
13
36
Advertisements

Demonstration


Previous
#1789 Beecrowd Online Judge Solution 1789 The Race of Slugs Solution in C++, Java, Js and Python
Next
#1794 Beecrowd Online Judge Solution 1794 Laundry Solution in C, C++, Java, Js and Python