CF913C.Party Lemonade

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity.

Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2_i_ - 1 liters and costs c__i roubles. The number of bottles of each type in the store can be considered infinite.

You want to buy at least L liters of lemonade. How many roubles do you have to spend?

新年派对没有柠檬水就不算新年派对!照例,你预计会迎来大量宾客,而购买柠檬水早已成为一件令人愉快的必需之事。

你最喜爱的商店以 $ n $ 种不同容量出售柠檬水,价格各不相同。第 $ i $ 种瓶子的容量为 $ 2^{i-1} $ 升,售价为 $ c_i $ 卢布。商店中每种瓶子的数量可视为无限。

你想至少购买 $ L $ 升柠檬水。你最少需要花费多少卢布?

输入格式

The first line contains two integers n and L (1 ≤ n ≤ 30; 1 ≤ L ≤ 109) — the number of types of bottles in the store and the required amount of lemonade in liters, respectively.

The second line contains n integers _c_1, _c_2, ..., c__n (1 ≤ c__i ≤ 109) — the costs of bottles of different types.

第一行包含两个整数 nn 和 LL(1≤n≤301 \leq n \leq 30;1≤L≤1091 \leq L \leq 10^9),分别表示商店中柠檬水瓶的种类数以及所需的柠檬水量(单位:升)。

第二行包含 nn 个整数 c1, c2, ..., cnc_1,\,c_2,\,...,\,c_n(1≤ci≤1091 \leq c_i \leq 10^9),表示不同种类瓶子的价格。

输出格式

Output a single integer — the smallest number of roubles you have to pay in order to buy at least L liters of lemonade.

输出一个整数——为购买至少 L 升柠檬水所需支付的最少卢布数。

输入输出样例

  • 输入#1

    4 12
    20 30 70 90

    输出#1

    150
  • 输入#2

    4 3
    10000 1000 100 10

    输出#2

    10
  • 输入#3

    4 3
    10 100 1000 10000

    输出#3

    30
  • 输入#4

    5 787787787
    123456789 234567890 345678901 456789012 987654321

    输出#4

    44981600785557577

说明/提示

In the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles.

In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles.

In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles.

在第一个例子中,您应购买一瓶 8 升装的柠檬水(90 卢布)和两瓶 2 升装的柠檬水(每瓶 30 卢布)。总计您将获得 12 升柠檬水,仅需 150 卢布。

在第二个例子中,尽管您仅需 3 升,但购买一瓶 8 升装的柠檬水(10 卢布)更为便宜。

在第三个例子中,最佳方案是购买三瓶 1 升装的柠檬水(每瓶 10 卢布),以 30 卢布获得 3 升柠檬水。

输入解题思路,AI测评打分。不知道怎么写?

首页