Sum the largest five numbers I'm doing a code-challenge problem:

Input
The first line consists of an integer T (T ≤ 100) which represents the number of test cases. Each test case consists of an integer N (5 ≤ N ≤ 100.000) which represents the number of integers, followed by a line that consists of N integers Ai (0 ≤ Ai ≤ 1000) separated by a space.
Output
For each test case, print in a line an integer that represents the sum of 5 largest numbers.

My code (below) works for small tests, but on the online judge, it resulted in Time Limit Exceeded. Some approaches I've tried that I think speed up the program (need confirmation):

Changing language from C++ to C (does it give significant boost?)
When calculating the sum, I use while instead of for loop (which one is more effective?)


#include &lt;stdio.h&gt;

int main () {
    int testCases;
    scanf(&quot;%d&quot;, &amp;testCases);
    
    for (int i = 1; i &lt;= testCases; i++) {
        int size, sum, temp, k, limit;
        sum = 0;
        temp = 0;
        scanf(&quot;%d&quot;, &amp;size);
        
        int array[size];
        
        for (int i = 0; i &lt; size; i++) {
            scanf(&quot;%d&quot;, &amp;array[i]);
        }
        
        for (int i = 0; i &lt; size; i++) {
            for (int j = i+1; j &lt; size; j++) {
                if (array[j] &lt; array[i]) {
                    temp = array[i];
                    array[i] = array[j];
                    array[j] = temp;
                } else {
                    continue;
                }
            }
        }
        
        k = size - 1;
        limit = size - 6;
        
        while (k &gt; limit) {
            sum += array[k];
            k--;
        }
    
        printf(&quot;%d\n&quot;, sum);
    }   
}
We need only 5 maximum elements, for that we don't need to sort whole array. We can use alternative approach

Approach 1: Use 5 local variables and keep track of minimum element in it.

Approach 2: Use Min-heap and insert first 5 elements of array in min-heap, then iterate on array from index = 5, if heap-root is smaller than number in array then extract that number from min-heap, and insert new.