You are not logged in. Please login at www.codechef.com to post your questions!

×

BIGSALE - Editorial

PROBLEM LINK:

Div1, Div2
Practice

Author: Praveen Dhinwa
Tester: Triveni Mahatha
Editorialist: Adarsh Kumar

DIFFICULTY:

Easy

PREREQUISITES:

None

PROBLEM:

You are given the initial price $p$ of a product. You need to first increase the price of this recipe by $x\%$ (from $p$) and then offer a discount of $x\%$. You need to compute the loss which occured to you as a result of this process, for $N$ items.

EXPLANATION:

Original price of the product = $p$.

Chef decides to increase the price of recipe by $x\%$ which means new price = $p.\left(1+\frac{x}{100}\right)$.

Now he is going to offer a discount of $x\%$ on this price. Hence,

Final price = $p.\left(1+\frac{x}{100}\right).\left(1-\frac{x}{100}\right)$
$\Rightarrow$ Final price = $p.\left(1-\left(\frac{x}{100}\right) ^2\right)$


Since, the final price is less than original price:
Loss = Original price - final price
$\Rightarrow$ Loss = $p - p.\left(1-\left(\frac{x}{100}\right) ^2\right)$
$\Rightarrow$ Loss = $p.\left(\frac{x}{100}\right) ^2$


Coming back to original problem, we can use the formula for loss computed above to find loss for each recipe individually. Hence,
Answer = $\sum \limits_{i=1}^N \text{quantity$_i$}.\text{price$_i$}.\left(\frac{\text{discount$_i$}}{100}\right) ^2$

Time Complexity:

$O(N)$

AUTHOR'S AND TESTER'S SOLUTIONS

Setter's solution
Tester's solution

This question is marked "community wiki".

asked 11 Mar, 16:57

adkroxx's gravatar image

7★adkroxx
306719
accept rate: 7%

edited 13 Mar, 15:06

admin's gravatar image

0★admin ♦♦
19.6k349497539


What is wrong? Please help!

https://www.codechef.com/viewsolution/17656727

link

answered 13 Mar, 15:03

i_say_hello's gravatar image

1★i_say_hello
11
accept rate: 0%

include<stdio.h>

int main()

{

int t;

scanf("%d",&t);

while(t--)

{

long n;

double l=0.0;

scanf("%ld",&n);

while(n--)

{

int q;

double np,ad,p,d;

scanf("%lf %d %lf",&p,&q,&d);

np=p+(pd0.01);

ad=np-(npd0.01);

l=l+(p-ad)*q;

}

printf("%lf\n",l);

}

return 0;

}

link

answered 25 Oct, 02:56

sivakishore434's gravatar image

0★sivakishore434
1
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×15,182
×3,673
×1,163
×265
×3

question asked: 11 Mar, 16:57

question was seen: 802 times

last updated: 25 Oct, 02:56