Codeforces 913 C. Party Lemonade (thinking) _ Common skills

Source: Internet
Author: User
Description

A New Year's party was not a new year's party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already a become pleasant.

Your Favorite Store sells lemonade in bottles to n different volumes at different costs. A single bottle of Type I has volume 2i−1 2^{i-1} liters and costs CI roubles. The number of bottles of each type in the store can be considered infinite.

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

Input

The contains two integers n and L (1≤n≤30 1≤l≤10^9)-the number of types of bottles in the store and The required amount of lemonade in liters, respectively.

The second line contains n integers c1, c2, ..., cn (1≤ci≤10^9)-the costs of bottles of different types.

Output

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

examples Input

4
20 30 70 90

examples Output

150

the

There are n n kinds of items, their size is 2i−1 2^{i-1}, the cost is CI c_i, the number of items is unlimited, now to make up the size of at least l goods, ask the minimum cost.

train of Thought

Because 2n−1x2=2n 2^{n-1} \times 2 = 2^n, we can think of whether small items made up of large items can bring a smaller cost.

So from small to large sweep to calculate the composition of the current size of 2i 2^i required the minimum cost, recorded as Ai a_i.

And then for size L l, we can convert it to binary, starting at the high level to the low,

Use now to record the cost of the high level of access, if the current bit is 1 1, now+=a[i] now+=a[i], because we can not combine the size of the goods with a larger than l l by this one,

If the current bit is 0 0, record Now+a[i] now+a[i], because at this point we only need to fill the bit to 1 1 to group the goods larger than L L.

Then find the minimum value.

AC Code

 #include <bits/stdc++.h> #define IO Ios::sync_with_stdio (false); \ cin.tie (0); \ cout
. Tie (0);
using namespace Std;
const int MAXN = 1E5+10;
const int mod = 1E9+7;

typedef long Long LL;
LL N,L,A[MAXN];
Bitset<32> SK;
Set<ll> ans;
    int main () {IO;
    cin>>n>>l;
    for (int i=0; i<n; i++) cin>>a[i];
    LL now = a[0];
        for (int i=1; i<32; i++) {now <<= 1;
        A[i] = I<n?min (A[i],now): now;
    now = A[i];
    SK = l;
    now = 0;
        for (int i=31; i>=0; i--) if (Sk[i]) now +=a[i];
    else Ans.insert (Now+a[i]);
    Ans.insert (now);
    Cout<<*ans.begin () <<endl;
return 0; }
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.