How does my code exceed the time limit?

I submitted my entry for the Maximum Special Sum problem (Code:MAXSPSUM). I ran it in the codeched IDE, ran fine, correct input and output too, Time says 0 second as seen here.

And yet when I submit it, it stays as submission queued for quite a while and says Time limit exceeded with Time being shown off as 3.01 seconds. I tried with a bunch of different inputs in VS and nothing takes too long at all. What am I doing wrong here?

My code

1 Like

Your loop is running from 0 to 2^n…thats why TLE?


So am I just not supposed to check through all the subsets?

1 Like

There is a better way to solve the problem. I haven’t seen the problem till yet but ya when you get a TLE, there is a way to optimize your solution.

Hint: Observe and see whether a pattern is there or not.

1 Like

WoW <3 :heart_eyes::heart_eyes::heart_eyes::heart_eyes::heart_eyes::heart_eyes: