Buy 2 Get 1 Free Problem Code: SALE2 | CodeChef Solution | Python3 смотреть онлайн
There is a sale going on in Chefland. For every 2 items Chef pays for, he gets the third item for free (see sample explanations for more clarity).
It is given that the cost of 1 item is X rupees. Find the minimum money required by Chef to buy at least N items.
Input Format
First line will contain T, number of test cases. Then the test cases follow.
Each test case contains of a single line of input, two integers N and X.
Output Format
For each test case, output the minimum money required by Chef to buy at least N items.
Constraints
1≤T≤1000
1≤N,X≤1000
Subtasks
Subtask 1 (100 points): Original constraints.
Sample Input 1
4
3 4
4 2
5 3
6 1
Sample Output 1
8
6
12
4
Explanation
Test Case 1: Chef wants 3 items where the cost of each item is 4 rupees. To minimise the expenditure, Chef can pay for 2 items and get the third item for free. This way, the total money required is 4⋅2=8 rupees.
Test Case 2: To minimise the expenditure, Chef can do the following:
Purchase 2 items for 2⋅2=4 rupees and get the third one free. Thus, the total number of items is 3.
Purchase 1 item for 2⋅1=2 rupees. Now Chef has total 4 items.
Thus, the minimum money required to buy 4 items is 4+2=6 rupees.
Test Case 3: To minimise the expenditure, Chef can do the following:
Purchase 2 items for 3⋅2=6 rupees and get the third one free. Thus, the total number of items is 3.
Purchase 2 items for 3⋅2=6 rupees. Chef gets a third item for free. Now Chef has total 6 items which is greater than his requirement of 5 items.
Chef wanted to buy at least 5 items. The minimum money required for that is 6+6=12 rupees.
Test Case 4: To minimise the expenditure, Chef can do the following:
Purchase 2 items for 1⋅2=2 rupees and get the third one free. Thus, the total number of items is 3.
Purchase 2 items for 1⋅2=2 rupees and get the third one free.. Now Chef has total 6 items.
Thus, the minimum money required to buy 6 items is 2+2=4 rupees.
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Buy 2 Get 1 Free Problem Code: SALE2 | CodeChef Solution | Python3» бесплатно и без регистрации, вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.