 # HELLO - Editorial

SIMPLE

Simple Math

### PROBLEM

• The default calling rate is D rokdas/minute.
• The usage pattern is U minutes/month.

There are N topups. They are numbered from 1 to N.

• The ith topup costs Ci rokdas
• The ith topup lasts Mi months
• The ith topup reduces the calling rate to Ri rokdas/minute

Find the topup that saves the most rokdas per month.

### EXPLANATION

We can find the default expense per month in rokdas/month

```COST = D * U
```

We can find the expense incurred when using a topup

```COSTi = Ri * U
```

but wait! A topup costs money and is only valid for Mi months. This cost can also be split across Mi months to find the cost per month. Hence

```COSTi = (Ci / Mi) + Ri * U
```

We can compare the costs and find the cheapest package.

### CODING COMMENTARY

It is already given that all topups generate a unique expense per month value.

There is one edge case where it is possible that none of the available topups produce a monthly cost that is less than the default one. It is clear from the statement that the intended answer in such cases is 0.

Note that it is possible that there is a plan that generates the same cost per month value as the deafult plan. This plan must not be considered!

Note that the topups are indexed from 1 to N, and not 0 to N-1.

### PSEUDO CODE

```e = D * U
ans = 0

for i = 1 to N
_e = Ci/Mi + Ri*U
if _e < e
e = _e
ans = i
```

### SETTER’S SOLUTION

Can be found here.

### TESTER’S SOLUTION

Can be found here.

1 Like

i am getting correct answer on code compile run but getting WA on submitting it.plzzzz help me

float min=10000;
float co,con;
co=DU;
int pos=0;
for(i=0;i<10;i++)
{
con=(cost
/month*) + Urate;

``````if(co>con && con<min)
{
min=con;
pos=i+1;

}
``````

}
cout<<pos;
}

Where do we submit our answers? New here pls help ^ ^