Блог пользователя salt_n_ice

Автор salt_n_ice, история, 4 года назад, По-английски

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?

  • Проголосовать: нравится
  • -11
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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