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.
23 lines
508 B
23 lines
508 B
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
|
|
int main() {
|
|
// 加快读入
|
|
ios::sync_with_stdio(false), cin.tie(0);
|
|
int s1 = 0, s2 = 0, s3 = 0, s4 = 0;
|
|
int n;
|
|
cin >> n;
|
|
while (n--) {
|
|
int x;
|
|
cin >> x;
|
|
if (x == 1) {
|
|
s1++;
|
|
s3 = max(s2 + 1, s3 + 1);
|
|
} else {
|
|
s2 = max(s1 + 1, s2 + 1);
|
|
s4 = max(s3 + 1, s4 + 1);
|
|
}
|
|
}
|
|
cout << max({s1, s2, s3, s4}) << endl;
|
|
return 0;
|
|
} |