首页 > 代码库 > Codeforces-A. Bear and Game(模拟)

Codeforces-A. Bear and Game(模拟)

Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.

Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.

You know that there will be n interesting minutes t1, t2, ..., tn. Your task is to calculate for how many minutes Limak will watch the game.

Input

The first line of the input contains one integer n (1 ≤ n ≤ 90) — the number of interesting minutes.

The second line contains n integers t1, t2, ..., tn (1 ≤ t1 < t2 < ... tn ≤ 90), given in the increasing order.

Output

Print the number of minutes Limak will watch the game.

Examples

input

3
7 20 88

output

35

input

9
16 20 30 40 50 60 70 80 90

output

15

input

9
15 20 30 40 50 60 70 80 90

output

90

Note

In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes.

In the second sample, the first 15 minutes are boring.

In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game.

Means:

boring时间超过15分钟(不包括)就会立即马上关掉电视,问他最多看电视几分钟

Solve:

直接模拟,考虑最后边界就行

Code:

技术分享
 1 #include <bits/stdc++.h> 2 using namespace std; 3 static const int MAXN = 99; 4 int data[MAXN]; 5 int n; 6 bool flag = 1; 7 int ans = 0; 8 int main() 9 {10     scanf("%d" , &n);11     for(int i = 1 ; i <= n ; ++i)12     {13         scanf("%d" , data + i);14         if(flag)15         {16             if(data[i] - data[i - 1] <= 15)17             {18                 ans = data[i];19             }20             else21             {22                 ans += 15;23                 flag = 0;24             }25         }26 27     }28     if(flag)29     {30         if(data[n] + 15 < 90)31             ans += 15;32         else33             ans = 90;34     }35     printf("%d\n" , ans);36 }
View Code

 

Codeforces-A. Bear and Game(模拟)