O(nlogn) solution in c++


#1

int Solution::solve(vector &A, int B) {
for (int i = 0; i < A.size(); i++)
{ if (i)
A[i] += A[i - 1];
}
int count = 0;
for (int l = 0; l < A.size(); l++)
{
count += distance(A.begin() + l, lower_bound(A.begin() + l, A.end(), (l > 0 ? A[l - 1] : 0) + B));
}
return count;
}


#2

its O(N^2) bcz distance function is O(N)