Can somebody tell me why this is getting TLE?

https://codeforces.com/contest/1311/submission/71861602
Can somebody help me where i went wrong?
(I know binary search is an option and i will implement that as well)
I was looking at @tmwilliamlin solution for the same question.
Is there a difference in speed between array and vector?

1 Like

Yes there is, array is fixed size thus the compiler can make it much faster.

2 Likes
 for(vector<int>check:v){

You’re creating a copy of each element of each element of v; try:

 for(vector<int>& check:v){

Edit:

Oh, wait - each such vector is tiny (just 3 elements) so it’s probably not that - although you should be doing it anyway :slight_smile:

Edit2:

Hmmm … actually, the speed up is quite significant, so definitely try it, after all :slight_smile:

3 Likes

https://codeforces.com/contest/1311/submission/71867863
this actually worked :smiley:
wow thanks a lot @ssjgz
i used to think this only sped up when i am accessing an array during function passing :sweat_smile:
@tmwilliamlin Well yeah my solution passed with almost same time with the method below but will learn this method as well XD

2 Likes

yeah you are correct

1 Like