CodeCraft-19 and Codeforces Round #537(Div. 2) C. Creative Snap 분리
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 2
. 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:
, divide the base into 2
amount of power, otherwise it takes his B⋅na⋅l amount of power, where na is the number of avengers and l
Output the minimum power needed by Thanos to destroy the avengers' base.
Input
The first line contains four integers n
, k, A and B (1≤n≤30, 1≤k≤105, 1≤A,B≤104), where 2n is the length of the base, k is the number of avengers and A and B
are the constants explained in the question.
The second line contains k
integers a1,a2,a3,…,ak (1≤ai≤2n), where ai
represents the position of avenger in the base.
Output
Output one integer — the minimum power needed to destroy the avengers base.
Examples
Input
Copy
2 2 1 2
1 3
Output
Copy
6
Input
Copy
3 2 1 2
1 7
Output
Copy
8
Note
Consider the first example.
One option for Thanos is to burn the whole base 1−4
with power 2⋅2⋅4=16
.
Otherwise he can divide the base into two parts 1−2
and 3−4
.
For base 1−2
, he can either burn it with power 2⋅1⋅2=4 or divide it into 2 parts 1−1 and 2−2
.
For base 1−1
, he can burn it with power 2⋅1⋅1=2. For 2−2, he can destroy it with power 1, as there are no avengers. So, the total power for destroying 1−2 is 2+1=3, which is less than 4
.
Similarly, he needs 3
power to destroy 3−4. The total minimum power needed is 6.
#include
#include
#include
#include
#include
#include
#include
#include
posted @
2019-02-10 15:24 NKDEWSM 읽기(
...) 설명(
...) 모음 편집
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.