▲ 8 r/codeforces
EDU DIV 2 B (greedy solution)
The observation i had was just find the smallest partition possible for first 2 by counting number of 1 in 1st half and when it exceeds no of 2s and 3s change boolean variable to true and close the 2nd partition with the same concept of counting nos of 1 and 2. Basically make the 2nd partition as soon as it is possible so that there is atleast 1 element left for 3rd partition.
Code:
void solve(){
int n;
cin>>n;
vector<int> v(n);
for(auto& x: v) cin>>x;
int count1=0;
int count23=0;
int count12=0;
int count3=0;
bool found=false;
bool found2=false;
int number;
for(int i=0;i<n;i++){
if(!found){
if(v[i]==2||v[i]==3){
count23++;
}else{
count1++;
if(count1>count23){
found=true;
if(v[i+1]==3) i++;
}else if(count1==count23 ) found=true;
}
}else if(!found2){
if(v[i]==3) count3++;
else{
count12++;
if(count12>=count3){
found2=true;
number=i;
break;
}
}
}
}
if(found && found2&& number!=n-1) cout<<"YES\n";
else cout<<"NO\n";
}
u/Dry_Resolution3449 — 23 hours ago