提交时间:2025-10-03 14:38:33

运行 ID: 38349

#include <algorithm> #include <iostream> using namespace std; using i64 = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; int f[6] = { 0, 0, 0, 0, 0, 0 }; for (int i = 1; i <= n; ++i) { int a; cin >> a; for (int j = 2; j < 6; ++j) f[j] = max(f[j - 1], f[j] + (j % 2 + 1 == a)); } cout << f[5] << '\n'; return 0; }