CF1260E.Tournament

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are organizing a boxing tournament, where nn boxers will participate (nn is a power of 22), and your friend is one of them. All boxers have different strength from 11 to nn, and boxer ii wins in the match against boxer jj if and only if ii is stronger than jj.

The tournament will be organized as follows: nn boxers will be divided into pairs; the loser in each pair leaves the tournament, and n2\frac{n}{2} winners advance to the next stage, where they are divided into pairs again, and the winners in all pairs advance to the next stage, and so on, until only one boxer remains (who is declared the winner).

Your friend really wants to win the tournament, but he may be not the strongest boxer. To help your friend win the tournament, you may bribe his opponents: if your friend is fighting with a boxer you have bribed, your friend wins even if his strength is lower.

Furthermore, during each stage you distribute the boxers into pairs as you wish.

The boxer with strength ii can be bribed if you pay him aia_i dollars. What is the minimum number of dollars you have to spend to make your friend win the tournament, provided that you arrange the boxers into pairs during each stage as you wish?

你正在组织一场拳击锦标赛,共有 nn 名拳手参赛(nn 是 22 的幂),而你的朋友是其中一员。所有拳手的实力互不相同,取值范围为 11 到 nn;拳手 ii 在与拳手 jj 的对决中获胜当且仅当 ii 的实力强于 jj。

锦标赛的赛制如下:nn 名拳手首先被分成 n2\frac{n}{2} 对;每对中实力较弱者被淘汰,实力较强者晋级下一轮;下一轮中剩余的 n2\frac{n}{2} 名拳手再次被任意配对,每对中的胜者继续晋级;如此反复,直至仅剩一名拳手(即最终冠军)。

你的朋友非常渴望赢得整个锦标赛,但他未必是实力最强的拳手。为了帮助他夺冠,你可以贿赂他的对手:若你的朋友在某场比赛中对阵一名已被你贿赂的拳手,则无论其实力高低,你的朋友都将获胜。

此外,在每一阶段,你都可以自由安排所有参赛拳手的配对方式。

贿赂实力为 ii 的拳手需花费 aia_i 美元。在你可以自由安排每轮配对的前提下,使你的朋友最终夺冠所需的最小花费是多少美元?

输入格式

The first line contains one integer nn (2≤n≤2182 \le n \le 2^{18}) — the number of boxers. nn is a power of 22.

The second line contains nn integers a1a_1, a2a_2, ..., ana_n, where aia_i is the number of dollars you have to pay if you want to bribe the boxer with strength ii. Exactly one of aia_i is equal to −1-1 — it means that the boxer with strength ii is your friend. All other values are in the range [1,109][1, 10^9].

第一行包含一个整数 nn(2≤n≤2182 \le n \le 2^{18})—— 表示拳击手的数量。nn 是 22 的幂。

第二行包含 nn 个整数 a1a_1, a2a_2, ..., ana_n,其中 aia_i 表示若想贿赂力量值为 ii 的拳击手所需支付的美元数。恰好有一个 aia_i 等于 −1-1 —— 这表示力量值为 ii 的拳击手是你的朋友。其余所有值均在区间 [1,109][1, 10^9] 内。

输出格式

Print one integer — the minimum number of dollars you have to pay so your friend wins.

输出一个整数——你至少需要支付的美元数量,以确保你的朋友获胜。

输入输出样例

  • 输入#1

    4
    3 9 1 -1

    输出#1

    0
  • 输入#2

    8
    11 -1 13 19 24 7 17 5

    输出#2

    12

说明/提示

In the first test case no matter how you will distribute boxers into pairs, your friend is the strongest boxer and anyway wins the tournament.

In the second test case you can distribute boxers as follows (your friend is number 22):

1:2,8:5,7:3,6:41 : 2, 8 : 5, 7 : 3, 6 : 4 (boxers 2,8,72, 8, 7 and 66 advance to the next stage);

2:6,8:72 : 6, 8 : 7 (boxers 22 and 88 advance to the next stage, you have to bribe the boxer with strength 66);

2:82 : 8 (you have to bribe the boxer with strength 88);

在第一个测试用例中,无论你如何将拳击手配对,你的朋友都是最强的拳击手,因此无论如何都会赢得锦标赛。

在第二个测试用例中,你可以如下分配拳击手(你的朋友编号为 22):

1:2,8:5,7:3,6:41 : 2, 8 : 5, 7 : 3, 6 : 4(拳击手 2,8,72, 8, 7 和 66 进入下一轮);

2:6,8:72 : 6, 8 : 7(拳击手 22 和 88 进入下一轮,你必须贿赂力量值为 66 的拳击手);

2:82 : 8(你必须贿赂力量值为 88 的拳击手);

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

首页