GDSUB-getting TLE

Can anyone help me review to optimize my code.It is giving tle in one of the test cases but the approach i followed seems similar to that in the editorial;
https://www.codechef.com/viewsolution/27403029

At a guess, it’s because you’re passing the N-length vector v by value on every call to fun:

int fun(long long int k,long long int p,long long int c[],vector<long long int> v /* <-- Ouch */)

Edit:

Just tried with your original code and with it modified to pass v via reference instead of value:

[~/devel/hackerrank/otherpeoples]>cat ../contests/codechef-september-2019b/chef-and-good-subsequences-testcase-random-large.txt | time -p ./a.out 
556506974
real 5.18
user 2.14
sys 2.77

vs

[~/devel/hackerrank/otherpeoples]>cat ../contests/codechef-september-2019b/chef-and-good-subsequences-testcase-random-large.txt | time -p ./a.out 
556506974
real 0.07
user 0.05
sys 0.00
2 Likes

Yep,it worked like charm!
Thanks a lot :slight_smile:!

1 Like