Getting only 70 points in this question?


#1

int Solution::seats(string A) {
long l;
long r;
bool f=true;
int c=0;
vector loc;
for(long i=0;i<A.length();i++){
if(A[i]==‘x’){
loc.push_back(i);
}
}
int x=loc.size();
if(x==0)return 0;
l=loc[0];
r=loc[loc.size()-1]-loc.size()+1;

long m;
long long int ans=INT_MAX;
long long int cur,cur2,cur3;
while(l<=r){
    m=(l+r)/2;
    cur=0;
    cur2=0;
    cur3=0;
    for(long i=m;i<m+x;i++){
        cur=(cur+(abs(i-loc[i-m])+10000003%10000003)+10000003)%10000003;
        if(l!=r){
            cur2+=(abs(i-1-loc[i-m]));
            cur3+=abs(i+1-loc[i-m]);    
        }
        
    }
    ans=min(ans,cur);
    if(cur2<=cur3)r=m-1;
    else l=m+1;
}
return (int)(ans%10000003);

}