salt_n_ice's blog

By salt_n_ice, history, 4 years ago, In English

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?

  • Vote: I like it
  • -11
  • Vote: I do not like it

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by salt_n_ice (previous revision, new revision, compare).