CF313C.Ilya and Matrix
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Ilya is a very good-natured lion. He likes maths. Of all mathematical objects, his favourite one is matrices. Now he's faced a complicated matrix problem he needs to solve.
He's got a square 2n×2n -sized matrix and 4n integers. You need to arrange all these numbers in the matrix (put each number in a single individual cell) so that the beauty of the resulting matrix with numbers is maximum.
The beauty of a 2n×2n -sized matrix is an integer, obtained by the following algorithm:
- Find the maximum element in the matrix. Let's denote it as m .
- If n=0 , then the beauty of the matrix equals m . Otherwise, a matrix can be split into 4 non-intersecting 2n−1×2n−1 -sized submatrices, then the beauty of the matrix equals the sum of number m and other four beauties of the described submatrices.
As you can see, the algorithm is recursive.
Help Ilya, solve the problem and print the resulting maximum beauty of the matrix.
输入格式
The first line contains integer 4n (1<=4n<=2⋅106) . The next line contains 4n integers ai (1<=ai<=109) — the numbers you need to arrange in the 2n×2n -sized matrix.
输出格式
On a single line print the maximum value of the beauty of the described matrix.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
输入输出样例
输入#1
1 13
输出#1
13
输入#2
4 1 2 3 4
输出#2
14
说明/提示
Consider the second sample. You need to arrange the numbers in the matrix as follows:
<br></br>1 2<br></br>3 4<br></br>
Then the beauty of the matrix will equal: 4 + 1 + 2 + 3 + 4 = 14.