# Help with Problem College Life 2

Can someone explain how this code is wrong?
Problem : CodeChef: Practical coding for everyone
Solution : CodeChef: Practical coding for everyone

It seems that if subtract q[i] every time( i.e, e times) and then finally add it once in the end(thus making it e-1 times), it gives a correct ans. Why?
Thank you.

My solution

This is my solution, I have took sum as sum of the total time used for watching one season, which I took as the sum of all time and then I subtracted (noOfEpisodes - 1)*intro[i] which means I subtracted the time skipped and then added it to total time.

Please anyone check and tell me what’s the problem in this solution It is giving TLE

the solution is giving a WA, not a TLE.
But yea, same as mine please explain.

@mimikyu_18 I changed everything from int/long to long long and submitted your code and it worked. submission. You declared the total sum variable as long and the sum variable as int. In c++ int and long have the same max limit.

If you want to use int then take a closer look on the constraints. I personally use long long everywhere thus eliminating the need.

2 Likes

Ok i got the error. dumb mistake on my part.

I GOT RE…can someone help

#include<stdio.h>

int main()
{
int t;

``````scanf("%d",&t);//test case
while(t>0)
{
long reduced=0,S,total=0;
scanf("%ld",&S);//seasons
long Q[S],E[S];
for(long i=0;i<S;i++)
{
scanf("%ld",&Q[i]);//intro
}
for(long i=0;i<S;i++)
{
scanf("%ld",&E[i]);//episodes
}
for(long i=0;i<S;i++)
{
total=total+E[i];//episodes
}
long L[S][total];
for(long i=0;i<S;i++)//for season
{
for(long j=0;j<E[i];j++)//for episodes
{
scanf("%ld",&L[i][j]);
}
}
long tl=0,result;
for(long i=0;i<S;i++)//for season
{
for(long j=0;j<E[i];j++)//for episodes
{
tl=tl+L[i][j];
}
}
for(long i=0;i<S;i++)
{
if(E[i]>1)
{
reduced=reduced+(Q[i]*(E[i]-1));
}
}
result=tl-reduced;

printf("%ld\n",result);

t--;
}
return 0;
``````

}

from what i understand, you have defined E of size S, which is incorrect.
the number of episodes will be the first number on every line.
You might want to read the problem description again.

just look at the way the input are given. you might be misguided the way sample input 1 is given, so just check the sample input 2 .Example->Let there are 2 seasons
you have to take input for intro song timing in next line(till this you have done correct). Then in the next line for the 1st season no of episode is given as input and next to it timing of each episodes are given as input(for 1st season only). Now similarly for second season its number of episode is given as input and next to it timing are given for each episodes of 2nd season only. COLGLF2 Problem - CodeChef

okay thank you