 # Chef and weird queries

this is the problem .
Here is what my solution was:

``````#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ll t;
cin>>t;
while(t--)
{
ll n,k;
cin>>n>>k;
ll queued=0;
bool gotit = false;
for(ll i=0; i<n; ++i)
{
ll x;
cin>>x;
queued= queued + (x-k);
if(queued<0)
{
cout<<i+1<<endl;
gotit = true;
break;
}
}
if(gotit)
continue;

if(queued>0)
{
cout<<n+1+queued/k<<endl;
}
else cout<<n+1<<endl;
}
}
``````

and as expected, it was giving correct results in test cases except for one, which was giving runtime error, the error which comes by the division of 0.
(and to be sure, I even tried running infinite loop if k==0, and then it showed TLE at the same test case.)
Now the thing is it is given k>0 and when I tried a little different technique, it was accepted.
So what is the problem here?

ANYONE?

Dude I have the same issue…
Let me know if you find the error…

My code is not perfect as it actually fetched me just 80 points.
here is what I did…
I summed up all the N numbers and divided it by the given K which gave me the Number of days after which the queries I’ll be left with will be less than K. So after ( (sum of all integers) / K + 1 ) days chef will answer queries less than K.

#include <bits/stdc++.h>
using namespace std;

int main()
{
long long int T; cin >> T;
while (T–)
{
long long int n, k; cin >> n >> k;
long long int sum = 0;
while (n–)
{
long long int a; cin >> a;
sum += a;
}

``````long long int val = sum / k + 1;
cout << val << endl;
``````

}
return 0;
}