Q:

Find middle element in Count sorted array

So, I have array like this:
a[1] = 2
a[4] = 3
a[8] = 1

which represent this sequence 1 1 4 4 4 8
And I need to find middle element, or element before (for odd and even);
In this example its 4.
How can I do this quick?
My code is very slow:
static int B(int[] array, int size) {       
    int c = 0;
    for (int i = 0; i < array.length; i++) {
        for (int j = 0; j < array[i]; j++) {
            c++;
            if (c == size / 2) {
                return i;    
            }
        }
    }   
}

A:

Traverse original array and add all values
a[1] = 2
a[4] = 3
a[8] = 1
sum = 6

Divide sum by 2 (find mid)
mid = 6/2 = 3

Traverse original array and subtract value from sum
check if ans <= 0
if true print index
else continue to next

