Choked so hard. Couldn’t solve B , took too much time on finding the “elegant” solution for A
What did I learn : Move on quickly
STOP CARING ABOUT RANK!!
Just solve A nd B quickly, warm up an hour before maybe. No pressure.
Even if you choke on B , quickly solve C , cause it is solvable for sure.
Question B
Almost solved , just needed to adjust the division factor Gave up on it logically during contest, stamina issue.
Question C
As soon as I saw minimum of maximum it clicked me that I can use binary search.
BS over possible answer. Max = imax individual blue elemnet.
Now this next step is not necessary , that i realised after looking at some solutions but
- Group similar colours together and take the max element from them.
- After that we have to check if “mid” can be the answer. To do that is the main question and a quite straightforeward one at that.
- Iterate as long as less than K . If greater than k increase count break, iterate from there till any number less than k is encountered.
- If count <= k , h = m
while(r-l>1){
ll m=(l+r)/2;
ll cnt=0;
REP(i,N)if(S[i]=='B'&&A[i]>m){
cnt++;
while(i<N&&(S[i]=='B'||A[i]<=m))i++;
i--;
}
if(cnt<=K)r=m;
else l=m;
}
cout<<r<<endl;