# Help me in solving BLDST problem

### My code

``````#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int m;
int n;
cin>>n>>m;
int a[m];
for(int i=0;i<m;i++)
{
cin>>a[i];
}
int res=m*n;
for(int j=0;j<m;j++)
{
res-=a[j];
}
// cout<<res<<endl;

if(res>n)
{
int b=res-n;
cout<<n-b<<endl;
}
else
{
cout<<n-res<<endl;
}

}
}
``````

Problem Link: BLDST Problem - CodeChef

@neelakshi12
@neelakshi12
I think the logic is not right.
it is for sure that in each box we can place at max M balls;
so u minimize it we will simply sum it up all the balls and divide it by n if the ceiling quotient is M then the answer would be sum%n else it would be 0.
This was my logic and i have coded it in a simpler way hope u will get it.
include <bits/stdc++.h>
using namespace std;

int main() {
int t;
cin>>t;
while(tâ€“)
{
long long int n,m;
cin>>n>>m;
long long int a[m];
long long int ans=0;
for(int i=0;i<m;i++)
{
cin>>a[i];
ans+=a[i];
}
long long int q=ceil(ans1.0/n1.0);
long long int r=ans%n;
if(r==0)
r=n;
if(q==m)
{
cout<<r<<endl;
}
else
cout<<0<<endl;
}
return 0;
}