0

I'm not Getting the language of question.Anyone?

Newton went to a mall. There are N items in a shop. For each i=1, 2, …, N, the price of the i- th item is Ai Rs. Newton has K coupons. Each coupon can be used on one item. You can use any number of coupons, possibly zero, on the same item. Using k coupons on an item with a price of a Rs allows him to buy it for max{a−kX, 0} Rs. Print the minimum amount of money Newton needs to buy all the items.

16th Jan 2023, 11:28 AM
Amit Joe
Amit Joe - avatar
11 Answers
+ 8
What are the inputs for this program? I assume you would have an int array that contains the prices of each item. We may assume that 1 piece of every item is bought. It was not mentioned, how much is the value of each coupon. Is this also an input? The formula max{a-kX, 0} expresses that we use a certain number of coupons to reduce the price, but we cannot pay less than 0 for each item (so there is no payback). It is not clear from the task description if the coupons should be applied to each item individually, or to the whole sum of all the prices (which would make more sense in a real life situation). If every coupon is worth 1 Rs and all prices are integers, then it doesn't matter. But if we have to apply coupons individually, then do we need to take into account that we should not waste too many coupons on fragments? Example, if an item costs 5 Rs and each coupon is 3 Rs, then do I want to use two coupons (causing myself a loss of 1 Rs) or just one? This task could be very simple or very complicated!
16th Jan 2023, 1:39 PM
Tibor Santa
Tibor Santa - avatar
+ 5
Amit Joe right, NOW you have given a complete description of the problem. I would write the solution like this. This is an optimization problem too. We must minimize the payment, so we need to find the best possible use for our coupons. First step is apply the coupons to those items where the price reduction will be the full value of the coupons. For this, we can loop through the array, and decrease each number as many times as it is divisible by the value of the coupon. For example if the coupon is worth 7 and the item costs 25, then use 3 coupons and decrease the price by 3*7 to 4. Then if we still have coupons left, then all the remaining prices are smaller than the coupon value, so we have to allocate the coupon to the most expensive ones first. We could do this, for example, by sorting the array of remaining prices in descending order, and keep applying coupons (reducing each price to zero) until we run out of coupons. Finally, summarize the remaining numbers that are present in the array.
16th Jan 2023, 6:35 PM
Tibor Santa
Tibor Santa - avatar
+ 5
Kotlin proof of concept. Obviously in C you won't be able to use these high level functions because they don't exist, but that's why I don't use C :) https://code.sololearn.com/cqCZ790Ddhv9/?ref=app
17th Jan 2023, 5:29 AM
Tibor Santa
Tibor Santa - avatar
+ 4
I still don't understand what are the inputs. For every test case you are showing two arrays of numbers. Can you explain what is happening in the first test case, how you get 12 as a result?
16th Jan 2023, 3:31 PM
Tibor Santa
Tibor Santa - avatar
+ 3
It looks like English 😊
16th Jan 2023, 12:36 PM
Tibor Santa
Tibor Santa - avatar
+ 2
Tibor Santa I understand. test case 1: 5 4 7 8 3 10 5 13 output:12 test case 2: 5 100 7 8 3 10 5 13 output: 0 test case 3: 20 815 60 2066 3193 2325 4030 3725 1669 1969 763 1653 159 5311 5341 4671 2374 4513 285 810 742 2981 202 output: 112 coupons are applied on the individual. i had made the code bt it exceed the time limit and for some test case it run time error
16th Jan 2023, 2:24 PM
Amit Joe
Amit Joe - avatar
+ 2
I don't code in C. I gave you a correct algorithm. If you post your code, there is a chance that someone will review it.
17th Jan 2023, 4:15 AM
Tibor Santa
Tibor Santa - avatar
+ 1
Tibor Santa i think you also didn't get it!! i know that it is English, I unable to understand that how to made code of this.?
16th Jan 2023, 1:15 PM
Amit Joe
Amit Joe - avatar
0
No of element:5 No of coupon:4 discount by one coupon:7 elements: 8 3 10 5 13 Tibor Santa
16th Jan 2023, 4:12 PM
Amit Joe
Amit Joe - avatar
0
I made the Code bt that's not so optimize so can you provide me a code
17th Jan 2023, 3:03 AM
Amit Joe
Amit Joe - avatar
0
ok
17th Jan 2023, 4:57 AM
Amit Joe
Amit Joe - avatar