# LONGCOOK - Editorial

1 Like

Try

Test case

1
1 201 2 201

I used the same approach as mentioned by you, but i got TLE.
@anon31329220 can you please tell me why i got TLE.
Here is my solution (CodeChef: Practical coding for everyone)

I have been trying this for days now, and still can’t figure out why my code is WA and TLE. I have used loop for only 400 years. Here is my code :- CodeChef: Practical coding for everyone

there’s a pattern for the overlapping feb years every 1,5,6,5,1,5,5, 1,5,6,5,1,5,5, 1,5,6,5,1,5,5, …

if it works , don’t touch it

can anyone here to help me to understand this plzzzz !!!1

If you don’t understand the quick explanation then read the full explanation

2 Likes

Java libraries could be slow, try to not use the libraries.

Try

Test case

1
12 205
1 207

I was attempting ’ Long Contest and Cook Off Overlaps
Approach: Using JAVA Calendar class.
Issue: Getting TLE Verdict.

I know JAVA Libs can be slow in this case, but still if anyone knows a way to get through this…

Kindly tell me whether I can approach this using Calendar class or not, if yes then how to optimize my code so to get AC.

I suspect that the Java Calendar class was not made for such big inputs.

Can you please make more clear to me what is meant by:

we will use the standard trick of splitting the range [l,r][l, r][l,r] into 2 prefixes: prefix r minus prefix l-1. This will make calculations simpler later on.

and also,

To pass the second subtask with…, … calculate the prefix sums. The prefix sums will allow us to answer queries in constant time.

I might be asking something too simple, but I am new to competitive programming and following editorials word by word, so ur answer matters in my learning curve.

Thanks.

1 Like

Both questions should be clear if you study prefix sums enough.

someone plese help me with this !! all test case are working correct but still wrong answer is coming

Using this fact, you can solve without regarding each month; the months are only necessary when checking whether the starting year and the ending year contains February. If the starting month is March or later, simply increase the starting year by one. Similarly, if the ending month is January, decrease the ending year by one. Then the answer is the number of years between them with their February satisfying one of the above conditons.