1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| #include <iostream> #include <algorithm> using namespace std; int main() { int n, x; scanf("%d", &n); int s1 = 0, s2 = 0, s3 = 0, s4 = 0; while (n--) { scanf("%d", &x); if (x == 1) { s1 = s1 + 1; s3 = max(s3 + 1, s2 + 1); } else { s2 = max(s2 + 1, s1 + 1); s4 = max(s4 + 1, s3 + 1); } } printf("%d\n", max(s3, s4)); return 0; }
|