Getting TLE on "Snake Eating" problem

Problem : Contest Page | CodeChef
my solution : Solution: 51962268 | CodeChef

learned from : SNAKEEAT | Snack Eating | CodeChef SnackDown 2021 Practice Contest- Beginners | Problem Solution - YouTube

I have followed that youtube tutorial for this problem. Whatever is described, I tried to follow that. He has explained code in python, and I used to code in C++. I did the same thing, but getting TLE.
Please help me to figure out.

Try taking these vectors:

helper(vector<int>vec, vector<lli>prefix,

by reference instead of by value.

1 Like

Now, I am getting wrong answer link
when used,

int helper(vector<int>&vec, vector<lli>&prefix, int k)


void solve(vector<int>&vec, int q)

Thank you @ssjgz. Now, my answer is accepted by replacing int by lli.
Thank you again.
Accepted solution link.

1 Like