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.
#include <iostream>
int main()
{
int t,n,know,to_know,days,sum,i;
scanf("%d",&t);
while(t--)
{
//n;
scanf("%d",&n);
int people[n];
for(int i = 0; i < n; ++i)
{
scanf("%d",&people[i]);
}
know = 1,to_know = people[0],days = 0;
while(n-know)
{
sum = 0,i = know;
for(; i < know+to_know&&i < n; ++i)
{
sum += people[i];
}
know = i;
to_know += sum;
days++;
}
printf("%d\n",days);
}
return 0;
}