www.codechef.com/problems/DEVUGRAP


#1

PLEASE CHECK THE LOGIC OF MY CODE AND LET ME KNOW WHERE IS THE ERROR IN THIS.

#include <stdio.h>

int main() {
int t;
long long int j,i;
scanf("%d",&t);
long long int r,m,sum=0,p,n,k,f;

for(i=0 ;i<t;i++)
{
    scanf("%lld %lld\n",&n,&k);
    int a[n];
    for(j=0;j<n;j++)
    {
       
        scanf("%11d",&a[j]);
        r=a[j]%k;
        m=a[j]/k;
        f=(m+1)*k;
        if(r>f-a[j])
        sum=sum+(f-a[j]);
        else
        sum=sum+r;
      
        
    }
  printf("%d\n",sum);  
  p=sum;
  sum=0;
  
}

return 0;

}