博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【CodeForces 1260E --- Tournament】
阅读量:2038 次
发布时间:2019-04-28

本文共 2325 字,大约阅读时间需要 7 分钟。

【CodeForces 1260E --- Tournament】

Description

You are organizing a boxing tournament, where n boxers will participate (n is a power of 2), and your friend is one of them. All boxers have different strength from 1 to n, and boxer i wins in the match against boxer j if and only if i is stronger than j.

The tournament will be organized as follows: n boxers will be divided into pairs; the loser in each pair leaves the tournament, and n2 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 i can be bribed if you pay him ai 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?

Input

The first line contains one integer n (2≤n≤218) — the number of boxers. n is a power of 2.

The second line contains n integers a1, a2, …, an, where ai is the number of dollars you have to pay if you want to bribe the boxer with strength i. Exactly one of ai is equal to −1 — it means that the boxer with strength i is your friend. All other values are in the range [1,109].

Output

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

Sample Input

4

3 9 1 -1

Sample Output

0

AC代码:

#include 
using namespace std;#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)#define endl '\n'using ll = long long;const int MAXN = (1<<18)+5;ll arr[MAXN];bool b[MAXN];int main(){
SIS; int n,x=1; cin >> n; for(int i=1;i<=n;i++) cin >> arr[i]; while(x<=n) b[x]=true,x<<=1; multiset
s; ll ans=0; for(int i=n;i>0;i--) {
if(arr[i]==-1) break; s.insert(arr[i]); if(b[i]) {
ans+=*s.begin(); s.erase(s.begin()); } } cout << ans << endl; return 0;}

转载地址:http://diyof.baihongyu.com/

你可能感兴趣的文章
Maven常用命令大全与pom文件讲解
查看>>
Java和JavaScript中使用Json方法大全
查看>>
Ubuntu14.04下安装docker
查看>>
ubuntu下安装nginx
查看>>
Linux 更改文件名
查看>>
Linux下安装Elasticsearch5.X
查看>>
linux命令ps aux|grep xxx详解
查看>>
MySQL常见问题
查看>>
Spring Boot 入门之缓存和 NoSQL 篇(四)
查看>>
使用Docker高效搭建开发环境
查看>>
微服务下的数据架构
查看>>
Nginx 容器教程
查看>>
linux下的命令: sudo ln -s 源文件 目标文件
查看>>
关于 Mybatis mapping.xml中的 StatementType 知识点
查看>>
小议“悲观锁和乐观锁”的原理、场景、示例
查看>>
面试中的这些坑,你踩过几个?
查看>>
socket,tcp,http三者之间的区别和原理
查看>>
Spring AOP 最热门面试题及答案
查看>>
Union和Union All到底有什么区别
查看>>
java读取txt文件,使用正则表达式获取信息
查看>>