How does my code exceed the time limit?

c

#1

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


#2

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


#3

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


#4

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.


#5

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