i am getting WA for my solution .please tell me what’s wrong here-

problem link-CodeChef: Practical coding for everyone

#include <bits/stdc++.h>

using namespace std;

int main() {

int t;

cin>>t;

while(t–){

int s;

cin>>s;

int q[s];

for(int i=0;i<s;i++){

cin>>q[i];

}

int a[100001];

int total=0;

int x;

for(int i=0;i<s;i++){

cin>>a[0];

x=a[0];

for(int j=1;j<=x;j++)

{cin>>a[j];

total=total+a[j]-q[i];

}

total=total+q[i];

}

cout<<total<<endl;

```
}
return 0;
```

}

total needs to be long long.

In Java array was also required to be long. I don’t know why even though test cases were within 100000.

@pravin_a_s Well the max number of episodes over one test case was 10^5 ( given by this line :

Sum of all Ei in a single testcase is at most 10^5). The length of every every episode <= 10^5(let it be 10^5 for each episode in worst case). Therefore total time = 10^5 * 10^5 = 10^10, which is clearly more than the the capacity of int, which is roughly 2*10^9 (seems to still fail around on anything more than 10^9).

i hope this helps

1 Like

Now I feel stupid. Thanks.

No I was talking about array and not sum.

see line 75 of both [CodeChef: Practical coding for everyone] and [CodeChef: Practical coding for everyone].

only difference in code is just in first one array is int while in second it is long.

are you sure? because another difference is on line 85(int X and long X).

when you do (X-1)*intro[i], you have to first store all of this somewhere. That somewhere will have to be inside the variable which is being operated on, namely X. and thus for the same reason as above, it will fail to store such large values(of the order 10^10 possibly).

Yeah You are right. Thanks.