Chef Easy Queries Problem Runtime Error

I wrote this code for the Chef Easy Queries Problem in CPP (Contest Page | CodeChef). It is satisfying the sample cases as well as all the test cases except one (the first test case). I have tried nearly everything, but that case just does not budge.

My algorithm -

  1. Input the values of T,n,k.

  2. Then run a loop T times. Inside this run another loop n times. In the inside loop, ask for Query (Q) and increment the day (day) by 1. Add it to the leftover queries from days before (left). From this quantity subtract (k). If it becomes negative, then break the loop and output the value of day we have.

  3. If the whole loop runs without (left) becoming negative, it means no free days till now. So, we increment the (day) variable by the quotient of (left) upon (k) plus 1.

This is our answer if (left) does not become negative.

I can’t find anything wrong with this, yet I am not able to solve the first test case of this problem. Any help would be appreciated.

using namespace std;

int main() {

long long int T;


for(long long int i=0;i<T;i++){

  long long int n,k,left=0,Q,day=0;
  for(long long int j=0;j<n;j++){


return 0;

This is my solution try to understand it .If still you are not able to understand reply to me. I will explain it to you

Thank you for replying, Aryan.

I saw your code and I think it has the same general idea as mine. I have used the variable left in place of w, day in place of c, and I have not used an array to store all numbers.

Honestly, I can’t find any difference between the logic of the two codes, and it seems to me that both should give the same answer for any test case.