You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
685 B

#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
int f[N][2];
int a[N];
int main() {
freopen("5.in", "r", stdin);
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
/*
8
1 2 8 3 3 4 4 5
10
8 1 1 2 3 4 5 6 7 8
10
3 2 2 5 5 6 2 2 1 1
*/
// 1、处理f[i][1]
for (int i = 1; i <= n; i++) {
if (a[i] == a[i - 1]) f[i][1] = a[i] + 1;
if (a[i] == f[i - 1][1]) f[i][1] = a[i] + 1;
}
// 2、处理f[i][0]
for (int i = 1; i <= n; i++) f[i][0] = max({a[i], f[i - 1][0], f[i - 1][1]});
cout << max(f[n][0], f[n][1]) << endl;
return 0;
}