CF1111C.Creative Snap

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.

Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of 22 . Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following:

  • if the current length is at least 22 , divide the base into 22 equal halves and destroy them separately, or
  • burn the current base. If it contains no avenger in it, it takes AA amount of power, otherwise it takes his BnalB \cdot n_a \cdot l amount of power, where nan_a is the number of avengers and ll is the length of the current base.

Output the minimum power needed by Thanos to destroy the avengers' base.

输入格式

The first line contains four integers nn , kk , AA and BB ( 1n301 \leq n \leq 30 , 1k1051 \leq k \leq 10^5 , 1A,B1041 \leq A,B \leq 10^4 ), where 2n2^n is the length of the base, kk is the number of avengers and AA and BB are the constants explained in the question.

The second line contains kk integers a1,a2,a3,,aka_{1}, a_{2}, a_{3}, \ldots, a_{k} ( 1ai2n1 \leq a_{i} \leq 2^n ), where aia_{i} represents the position of avenger in the base.

输出格式

Output one integer — the minimum power needed to destroy the avengers base.

输入输出样例

  • 输入#1

    2 2 1 2
    1 3
    

    输出#1

    6
    
  • 输入#2

    3 2 1 2
    1 7
    

    输出#2

    8
    

说明/提示

Consider the first example.

One option for Thanos is to burn the whole base 141-4 with power 224=162 \cdot 2 \cdot 4 = 16 .

Otherwise he can divide the base into two parts 121-2 and 343-4 .

For base 121-2 , he can either burn it with power 212=42 \cdot 1 \cdot 2 = 4 or divide it into 22 parts 111-1 and 222-2 .

For base 111-1 , he can burn it with power 211=22 \cdot 1 \cdot 1 = 2 . For 222-2 , he can destroy it with power 11 , as there are no avengers. So, the total power for destroying 121-2 is 2+1=32 + 1 = 3 , which is less than 44 .

Similarly, he needs 33 power to destroy 343-4 . The total minimum power needed is 66 .

首页