CHEFGR-Editorial

First find the max of the array then find sum of how many each element of the array is short of max element…if this sum is greater than m then its false…otherwise check condition (m - sum) %n ==0
if it is true print yes else print false

#include<stdio.h>

#define s(a) scanf("%ld",&a)
typedef long int li;

int main()
{
li t,n,m,h[1024],i;

s(t);
while(t--){
	s(n); s(m);
	
	li max = 0;

	for(i=0; i<n; i++){
		s(h[i]);

		if( h[i] > max )
			max = h[i];
	}

	li sum = 0;

	for(i=0; i<n; i++)
		sum += ( max - h[i] );

	if( sum > m )
		printf("No\n");
	else
		( (m-sum) % n == 0 ) ? printf("Yes\n") : printf("No\n");
}
return 0;

}

thanks for sharing this post


Australian Assignment Help

I do not know it is giving wrong answer

/* package whatever; // don’t place package name! */

import java.util.;
import java.lang.
;
import java.io.*;
class Cool
{
public static void main (String[] args) throws java.lang.Exception
{ Scanner sc=new Scanner(System.in);
int t;
t=sc.nextInt();
for(int j=0;j<t;j++)
{ int n,h,m;
n=sc.nextInt();
m=sc.nextInt();
int a[]=new int[n+1];
int max=0;
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
if(a[i]>max)
max=a[i];
}
int count=0;
for(int i=0;i<n;i++)
{ count+=max-a[i]; }
// cout<<count<<" ";
if(m-count>=0&&(m-count)%n==0)
System.out.println(“YES”);
else
System.out.println(“NO”);
}

}

}