I need your help in understand the line paragraph of the editorial of Problem - 1556C - Codeforces
The next observation is that if we fix the number of opening brackets taken from ππcl, then we can count the number of brackets that we should take from ππcr. Using these observations we can calculate the answer for πβ¦πlβ¦r using the following formula: πππ(ππ,ππβπππππππ)βπππ₯(1,ππππ΅ππππππ)+1min(cl,crβbalance)βmax(1,minBalance)+1.
Could someone elaborate this formula possibly provide an example to understand it better?
AC Solution: Status - Codeforces
In the solution, please explain the left and right equations i.e; what exactly they are calculating
static long solve(int []c, int n){
long ans=0;
for(int l=0;l<n;l+=2){
long min_balance=c[l];
long balance=c[l];
for(int r=l+1;r<n;r++){
if(r%2==0){
// adding the open brackets to cur
balance+=c[r];
}else{
//
long left=Math.max(0, balance-c[r]);
long right=Math.min(min_balance, Math.min(balance-1, c[l]-1));
if(left<=right){
ans+=right-left+1;
}
// removing closed brackets from open
balance-=c[r];
min_balance=Math.min(min_balance, balance);
}
}
}
return ans;
}