CodeForces - 366C
Description Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something. Dima and Seryozha have n fruits in the fridge. Each fruit has two parameters: the taste and the number of calories. Inna decided to make a fruit salad, so she wants to take some fruits from the fridge for it. Inna follows a certain principle as she chooses the fruits: the total taste to the total calories ratio of the chosen fruits must equal k. In other words, Inna hasn't chosen the fruits yet, she is thinking: what is the maximum taste of the chosen fruits if she strictly follows her principle? Help Inna solve this culinary problem — now the happiness of a young couple is in your hands! Inna loves Dima very much so she wants to make the salad from at least one fruit. Input The first line of the input contains two integers n, k(1 ≤ n ≤ 100, 1 ≤ k ≤ 10). The second line of the input contains nintegers a1, a2, ..., an(1 ≤ ai ≤ 100) — the fruits' tastes. The third line of the input contains n integers b1, b2, ..., bn(1 ≤ bi ≤ 100) — the fruits' calories. Fruit number i has taste ai and calories bi. Output If there is no way Inna can choose the fruits for the salad, print in the single line number -1. Otherwise, print a single integer — the maximum possible sum of the taste values of the chosen fruits. Sample Input
Input
3 2 10 8 1 2 7 1
Output
18
Input
5 3 4 4 4 4 4 2 2 2 2 2
Output
-1 Hint In the first test sample we can get the total taste of the fruits equal to 18 if we choose fruit number 1 and fruit number 2, then the total calories will equal 9. The condition In the second test sample we cannot choose the fruits so as to follow Inna's principle. //题意: 在一个水果篮里有n种水果,并且这些水果每一种都有一个美味度和一个卡路里的属性,
|
CodeForces - 366C Dima and Salad (DP&01背包)
最新推荐文章于 2022-08-29 19:55:25 发布

在这个CodeForces挑战中,Dima、Inna和Seryozha聚集在一起,Inna决定为Seryozha做一道水果沙拉来激励他散步。他们有n种水果,每种水果都有特定的美味度和卡路里。Inna想要挑选一些水果,使得挑选的水果的美味度与卡路里之比等于给定的比例k。挑战在于找出最大可能的美味度总和,或者判断是否有可能达到这样的比例。通过转化问题为01背包问题,读者可以理解如何解决这个烹饪数学难题。
677

被折叠的 条评论
为什么被折叠?



