#include <bits/stdc++.h>
using namespace std;
vector<int>v;
vector<int>slm;
int main() {
int n;
cin>>n;
int x,y;
int r=n;
while(r--){
cin>>x>>y;
v.push_back(x);
slm.push_back(y);
}
int tab[n];
tab[0]=1;
int t[n];
t[0]=1;
for(int so=1;so<n;so++){
t[so]=1;
tab[so]=0;
if(v[so]==1 or v[so]==0){
if(so>=2){
if(slm[so-2]<=1){
t[so]+=tab[so-2];}
}
}
if(v[so]==0){
if(slm[so-1]==0){
t[so]=max(t[so],tab[so-1]+1);}
}
if(so>=3){
t[so]=max(t[so],tab[so-3]+1);}
tab[so]=max(tab[so-1],t[so]);
}
sort(tab,tab+n);
cout<<tab[n-1]<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |