In SnackDown 2018, there is a question Spread the Word(Code SPREAD2). There you have to loop through an array of people(I cannot think of anything better) and sum the number of people they can tell about SnackDown iteratively. Here is my code which is getting a TLE. Please help.
for(int i = 0; i < n; ++i)
know = 1,to_know = people,days = 0;
sum = 0,i = know;
for(; i < know+to_know&&i < n; ++i)
sum += people[i];
know = i;
to_know += sum;
You’ll get to know the correct approach after 7:30 pm tomorrow.
Till then, try hard. And avoid asking for hints on forums.You might get banned for this.
OK, thanks for the warning! I just saw std::accumulate(). Let’s try that!
PS BTW, I can ask for answer/approach/hints if it is not part of a competition or competition is over, right?
Well, I did this, but now SIGSEGV???
sum = std::accumulate(people + know,people + (know+to_know < n? know+to_know : n) , to_know);
know = (know + to_know < n ? know + to_know : n);
to_know = sum;
PS Waiting for answer after 7:30 pm tomorrow.
@jal_super123 Yes. You can ask any query after contest is over.