Help me debug it


#1

I am getting a TLE. Can someone tell me where I am going wrong?

public class Solution {
static long c=0;
public static void merge(int A[],int l,int m,int h)
{ int p1=l,p2=m+1,k=0;
int b[]=new int[h-l+1];
while(p1<=m && p2<=h)
{ if(A[p1]>A[p2])
{ b[k++]=A[p2++];
c+=(m-p1+1);
c=c%1000000007;
}
else
b[k++]=A[p1++];
}
while(p1<=m)
b[k++]=A[p1++];
while(p2<=h)
b[k++]=A[p2++];
for(int z=l;z<=h;z++)
A[z]=b[z-l];
}
public static void ms(int A[],int l,int h)
{ while(l<h)
{ int m=(l+h)/2;
ms(A,l,m);
ms(A,m+1,h);
merge(A,l,m,h);
}
}
public int solve(int[] A) {
ms(A,0,A.length-1);
return (int)c;
}
}