Question description APPU needed a laptop, so he went to a neighbouring garage sale. At a sale, there were n laptops. The cost of a laptop with index i is ai rupees. Some laptops have a negative price, meaning their owners are willing to pay APPU if he buys their broken laptop. APPU is free to purchase whichever laptop he desires. Despite his strength, he can only handle m Laptops at a time, and he has no desire to return to the auction. Please, help APPU find out the maximum sum of money that he can earn. Constraints: 1≤T≤10 1≤n,m≤100 -1000≤ai≤1000 Input Format: First line of the input contains T denoting the number of test cases.Each test case has 2 lines : first line has two spaced integers n m. second line has n integers [a0...ai...an-1].
C Program

#include <stdio.h>

void bubble_sort(int arr[],int no)
{
    int i,j,temp;
    for(i=0;i<no-1;i++)
    {
        for(j=0;j<no-i-1;j++)
        {
            if(arr[j]>arr[j+1])
            {
                temp=arr[j];
                arr[j]=arr[j+1];
                arr[j+1]=temp;
            }
        }
    }
}

int MEGA_SALE(int arr[],int no,int k)
{
    int i,sum=0;

    bubble_sort(arr,no);

    for(i=0;i<k;i++)
    {
        if(arr[i]<0)
            sum+=-arr[i];
        else
            break;
    }

    return sum;
}

int main()
{
    int T;
    scanf("%d",&T);

    while(T--)
    {
        int n,m,i;
        scanf("%d %d",&n,&m);

        int arr[100];
        for(i=0;i<n;i++)
            scanf("%d",&arr[i]);

        printf("%d\n",MEGA_SALE(arr,n,m));
    }

    return 0;
}