Chef and weird queries

Revision en4, by salt_n_ice, 2020-10-13 17:30:57

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?

Tags #help, #debug, #easy, #general

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en4 English salt_n_ice 2020-10-13 17:30:57 18
en3 English salt_n_ice 2020-10-13 17:29:42 12
en2 English salt_n_ice 2020-10-13 17:28:59 2 Tiny change: '\n }\n}~~~~~\nand' -> '\n }\n}\n~~~~~\nand'
en1 English salt_n_ice 2020-10-13 17:28:12 1192 Initial revision (published)