原题:
E. Tournament
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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≤2^18) — 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,10^9].

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

Examples
input
4
3 9 1 -1
output
0
input
8
11 -1 13 19 24 7 17 5
output
12
Note
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 2):

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

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

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

中文:

你朋友参加拳击比赛,想拿冠军,可以通过贿赂对手实现。一共有n个人参加比赛,每个人都给出可以被贿赂的金额,每个人的顺序按照能力值排序。
现在让你安排比赛,即两两配对赛,输的淘汰。最少贿赂多少钱能拿冠军。 -1表示自己

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;typedef pair<int,int> pii;
const int maxn = 1000001;int n;
ll a[maxn];
map<int,bool> match;
int main()
{ios::sync_with_stdio(false);while(cin>>n){match.clear();for(int i=1;i<=n;i++)cin>>a[i];priority_queue<ll,vector<ll>,greater<ll>> Q;for(int i=1;i<=n;i<<=1)match[i]=true;ll ans = 0;for(int i=n;i>=1&&a[i]>0;i--){Q.push(a[i]);if(match[i]){int top = Q.top();Q.pop();ans+=top;}}cout<<ans<<endl;}return 0;
}

解答:

第一轮,可以挑所有选手作为对手。
第二轮,可以挑第1个到第n作为,对手,因为第一个选手能力最弱,无论和谁比赛都会被淘汰。
第三轮,可以挑[5,n]个,因为前四个选手肯定会被淘汰,以此类推

每次在对应轮数的比赛时挑选剩余的人中被贿赂的钱最少的人比赛即可。

cf Educational Codeforces Round 77 E. Tournament相关推荐

  1. cf Educational Codeforces Round 133 C. Robot in a Hallway

    原题: There is a grid, consisting of 2 rows and m columns. The rows are numbered from 1 to 2 from top ...

  2. cf Educational Codeforces Round 85 (Rated for Div. 2)B. Middle Class

    题目链接:https://codeforces.com/contest/1334/problem/B B. Middle Class time limit per test2 seconds memo ...

  3. Educational Codeforces Round 77 (Rated for Div. 2)A~C[数学场]

    A. Heating 题目大意:就是给你一个数n把它分成k份始得每一份的平方和最小: 思路:1.如果k足够大那么将n分成n个1平方和为n是最小的 2.如果k < n,我们还是从第一点出发,先将n ...

  4. Educational Codeforces Round 77 (Rated for Div. 2) C. Infinite Fence 数论

    传送门 文章目录 题意: 思路: 题意: 思路: 碰到这样的题肯定是先写几个找找规律了,随便写几个就可以发现是以lcm(a,b)lcm(a,b)lcm(a,b)为一个循环,所以我们只需要在一个周期lc ...

  5. Educational Codeforces Round 77 (Rated for Div. 2) D. A Game with Traps 贪心 +二分

    传送门 文章目录 题意: 思路: 题意: 给你nnn个人,每个人都有个能力值aia_iai​.让后在1−m1-m1−m的路上有kkk个陷阱,每个陷阱的范围是[li,ri][l_i,r_i][li​,r ...

  6. CF Educational Codeforces Round 57划水记

    因为是unrated于是就叫划水记了,而且本场也就用了1h左右. A.B:划水去了,没做 C:大水题,根据初三课本中圆的知识,可以把角度化成弧长,而这是正多边形,所以又可以化成边数,于是假设读入为a, ...

  7. cf Educational Codeforces Round 49 D. Mouse Hunt

    原题: Medicine faculty of Berland State University has just finished their admission campaign. As usua ...

  8. cf Educational Codeforces Round 54 C. Meme Problem

    原题: C. Meme Problem time limit per test1 second memory limit per test256 megabytes inputstandard inp ...

  9. cf Educational Codeforces Round 134 E. Prefix Function Queries

    原题: You are given a string s, consisting of lowercase Latin letters. You are asked q queries about i ...

最新文章

  1. mysql sqlserver对比_很用心的写了 9 道 MySQL 面试题
  2. System V的启动风格和BSD的启动风格(2)---代码角度
  3. 关于fseek不能定位大于2G文件的问题
  4. android nio debug模式正常 release包crash_Flutter包大小治理上的探索与实践
  5. FileTracker:error FTK1011编译错误的原因和解决办法
  6. 【flink】flink作业超额启动多个taskManager k8s
  7. 11.4 final类
  8. pythonchar中的拟合方法_Python 字符串中常见的一些方法
  9. 【笔记+总结】Andrew Ng-神经网络和深度学习
  10. Linux自动配置部署,企业级自动化部署方案——ansible实现tomcat自动安装和配置,...
  11. Python 机器学习经典实例
  12. 基于exchange 2010迁移exchange 2016搭建共存环境
  13. 阿里人工智能实验室AIoT总架构,15 年工龄的资深技术专家职场历程自述
  14. 三种嵌入式操作系统比较
  15. 框架学习(1)——service层,dao层和service实现类进行数据库操作
  16. Visio--用例图、类图、顺序图、活动图
  17. 【Hive】Beeline CLI介绍
  18. office 论文 页码_毕业论文word里面怎么弄以下这些页码?第一页不显示。 第二三页是I II ,四页开始以下是1234。求详细方法...
  19. 经典书籍亲子共读云端相约共沐书香
  20. IntelliJ IDEA 等软件 激活

热门文章

  1. web——14.web开发
  2. 触摸屏登录的几种方式
  3. fix函数怎么使用matlab,Matlab基本函数-fix函数
  4. Android消息推送
  5. Parcelable的使用
  6. 【观察】与时俱进提供智慧费用管理新体验,SAP Concur “以行践言”的新价值...
  7. HTML中利用404将老域名重定向到新域名
  8. 灰色关联分析及MATLAB实现
  9. 2020年的第二周 | 关于赚钱 ——《副业赚钱》、基金定投
  10. 从零开始写STM32平衡小车代码,从0到1