当前位置:网站首页>牛牛的组队竞赛
牛牛的组队竞赛
2022-07-03 11:02:00 【爱敲代码的小邢~】
【题目】
【组队竞赛】
牛牛举办了一次编程比赛,参加比赛的有3*n个选手,每个选手都有一个水平值a_i.现在要将这些选手进行组队,一共组成n个队伍,即每个队伍3人.牛牛发现 队伍的水平值等于该队伍队员中第二高水平值。
例如: 一个队伍三个队员的水平值分别是3,3,3.那么队伍的水平值是3 一个队伍三个队员的水平值分别是3,2,3.那么队伍的水平值是3 一个队伍三个队员的水平值分别是1,5,2.那么队伍的水平值是2 为了让比赛更有看点,牛牛想安排队伍使所有队伍的水平值总和最大。 如样例所示: 如果牛牛把6个队员划分到两个队伍,如果方案为: team1:{1,2,5}, team2:{5,5,8}, 这时候水平值总和为7. 而如果方案为: team1:{2,5,8}, team2:{1,5,5}, 这时候水平值总和为10. 没有比总和为10更大的方案,所以输出10.
输入描述:
输入的第一行为一个正整数n(1 ≤ n ≤ 10^5) 第二行包括3*n个整数a_i(1 ≤ a_i ≤ 10^9),表示每个参赛选手的水平值。
输出描述:
输出一个整数表示所有队伍的水平值总和最大值。
示例1:
输入:
2
5 2 8 5 1 5
输出:
10
【思路】
先对所有的水平值排降序,然后从第一个位置依次取两个数,这两个数分别是一个组中的最高水平和中间水平,总共取n组。

【代码】
#include<iostream>
#include<algorithm>
using namespace std;
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
long long n;
long long ans=0;
cin>>n;
long long* arr=new long long[3*n];
for(long long i=0;i<3*n;i++)
cin>>arr[i];
sort(arr,arr+3*n,cmp);
for(long long i=1;i<2*n;i+=2)
ans+=arr[i];
cout<<ans<<endl;
return 0;
}
边栏推荐
- How PHP solves the problem of high concurrency
- MCDF实验1
- Machine learning 3.2 decision tree model learning notes (to be supplemented)
- 并发编程-单例
- Viewing binary bin files with notepad++ editor
- [OBS] configFile in ini format of OBS
- Web安全总结
- The tutor put forward 20 pieces of advice to help graduate students successfully complete their studies: first, don't plan to take a vacation
- 836. 合并集合(DAY 63)并查集
- C language AES encryption and decryption
猜你喜欢

FL Studio 20无限试用版水果编曲下载

C语言 AES加解密

【学习笔记】dp 状态与转移

Numpy np. Max and np Maximum implements the relu function

多维度监控:智能监控的数据基础

Based on MCU, how to realize OTA differential upgrade with zero code and no development?

How to get started embedded future development direction of embedded

银泰百货点燃城市“夜经济”

ASP.NET-酒店管理系統

金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~
随机推荐
基于turtlebot3实现SLAM建图及自主导航仿真
R语言使用原生包(基础导入包、graphics)中的hist函数可视化直方图(histogram plot)
JGG专刊征稿:时空组学
ArcGIS应用(二十一)Arcmap删除图层指定要素的方法
Processes and threads
一些常用术语
C language log base zlog basic use
How to become a senior digital IC Design Engineer (1-5) Verilog coding syntax: operand
R language uses grid of gridextra package The array function combines multiple visual images of the lattice package horizontally, and the ncol parameter defines the number of columns of the combined g
2022年中南大学夏令营面试经验
Dynamic programming (interval DP)
R语言ggplot2可视化:gganimate包创建动态折线图动画(gif)、使用transition_reveal函数在动画中沿给定维度逐步显示数据、在折线移动方向添加数据点
动态规划(区间dp)
外插散点数据
Repo ~ common commands
Solicitation for JGG special issue: spatio-temporal omics
Abandon the Internet after 00: don't want to enter a big factory after graduation, but go to the most fashionable Web3
Use typora to draw flow chart, sequence diagram, sequence diagram, Gantt chart, etc. for detailed explanation
P3250 [hnoi2016] Network + [necpc2022] f.tree path tree section + segment tree maintenance heap
How to become a senior digital IC Design Engineer (1-4) Verilog coding syntax: expression