Home c++ Task from E-OLYMP: The minimum amount for the purchase of disks

Task from E-OLYMP: The minimum amount for the purchase of disks

Author

Date

Category

Condition Tasks :

Clean CDs sell in three types of packages. Packaging of 100 disks costs 100 UAH., Out of 20 disks – 30 UAH., And one disk costs 2 UAH. What minimum amount need to be spent to buy n such disks?

It seems to be solved, the tests are executed correctly, but E-Olymp does not count on 100%. What is the problem?

# include & lt; stdio.h & gt;
INT MAIN (Void) {
  int n;
  Scanf ("% d", & amp; n);
  PrintF ("% d", (n / 100 * 100) + (n% 100/20 * 30) + (N% 100% 20 * 2));
  Return 0;
}

Answer 1, Authority 100%

You do not consider that, for example, buy 19 disks – cheaper than a pack for 30 hryvnias than one disk 2 hryvnia …

Simple and freaky – just compare options …

int main (int argc, char * argv [])
{
  int n;
  CIN & GT; & GT; n;
  INT D100 = N / 100, D20 = N% 100/20, D1 = N% 20;
  int s = d100 * 100 + d20 * 30 + d1 * 2;
  int m = d100 * 100 + (d20 + 1) * 30;
  int k = (D100 + 1) * 100;
  if (s & gt; m) s = m;
  if (S & gt; k) s = k;
  COUT & LT; & LT; s;
}

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions