Chef and Ground Problem, Code: CHEFGR

The following code gives NZEC error, I am not able to figure out why. Somebody please help.

#include <iostream>

using namespace std;

int main()
{
    int t;
    cin>>t;
    if(t>100 || t<1) return 1;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        if(n>100 || n<1) return 1;
        if(m>10000 || m<1) return 1;
        int a[n]; int max=1;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
            if(a[i]>100 || a[i]<1) return 1;
            if(a[i]>max) max=a[i];

        }
        int sum=0;
       for(int i=0;i<n;i++)
        {
           while(a[i]!=max)
            {
                a[i]=a[i]+1;
                sum++;
            }

        }

       if(sum>m)
        cout<<"No"<<endl;
       else if(sum<m)
       {
           if((m-sum)%n==0)
            cout<<"Yes"<<endl;
           else
            cout<<"No"<<endl;
       }
       else
        cout<<"Yes"<<endl;

}
return 0;
}

y r u checking the inputs being in the constraint range and then returning 1…remove that…it is made sure that the inputs are within the constraints u dont need to check them!!!

1 Like

(as pointed by @kunal361) simply remove all the conditions you’ve used to check input… you’ll get AC…

Corrected Version of your code

1 Like