# HWRK - Editorial

Problem link : Homework | CodeChef

Problem Statement :
Chef is famous for his laziness at school. He always leaves things to last minute. Now Chef has N problems in the assignment of “Advanced topics in algorithm” class to solved. The assignment is due tomorrow and as you may guess he hasn’t touch any of the problems. Fortunately he got a plan as always.

The first step will be buying a pack of Red Bull and then to work as hard as he can. Here is how he is going to spend the remaining time:

Chef will not take a break until he finishes at least half of the remaining problems. Formally, if N is even then he will take he first break after finishing N/2 problems. If N is odd then the break will be after he done (N+1)/2 problems. Each of his break will last for B minutes. Initially, he takes M minutes in solving a problem, after each break he will take twice more time in solving a problem, i.e. 2∗M minutes per problem after the first break.

Chef will start working soon and ask you to help him calculate how much time it will take until he finish the last problem!

Solution :

``````#include <stdio.h>

int main()
{long long int i,n,m,b,t,T;
scanf("%lld",&T);
for(i=0;i<T;i++)
{t=0;
scanf("%lld",&n);

scanf ("%lld",&b);
scanf ("%lld",&m);

while(n>=1)
{if (n%2==0)
{t=t+((n/2)*m+b);
n=(n-(n/2));}
else if (n==1)
{t=t+((1)*m);
n=0;
}
else{(t=t+((n+1)/2*m+b));
n=n-((n+1)/2);}

m=m*2;}
printf("%lld",t);
printf("\n");
}
return 0;
}
``````