https://www.codechef.com/problems/MAXDIFF

,

my code is running successfully for numerous test cases but the portal is showing that my answer is wrong and I don’t know what’s wrong in it. help.

https://www.codechef.com/problems/MAXDIFF

#include <stdio.h>

int main(void) {

int t;
	scanf("%d\n",&t);


int n,i=0, j=0, b=0, k;

for(int g=1;g<=t;g++)
{
scanf("%d %d\n",&n,&k);
int a[n];

for(i=0; i<n; i++){
    scanf("%d ",&a[i]);
   // printf("%d ",a[i]);
}

for(i=1; i<=n; i++){
    for(j=0; j<n-1; j++){
        if(a[j]>a[j+1]){
            b= a[j+1];
            a[j+1]= a[j];
            a[j] = b;
        }
    }
}
int sum1 =0, sum2 = 0;

for(i=0; i<k; i++){
    sum1 = sum1 + a[i];
}
for(i=k;i<n;i++){
     sum2 = sum2 + a[i];
}
printf("%d\n",sum2-sum1);

}

return 0;

}

Silly me :slight_smile: Consider the test input:

1
3 2
100 100 1
1 Like

Please format your code by pasting your code here, then select your code and press </> button on the top.

thanx, i never thought father would want to do that to the child xD.

1 Like