当前位置:网站首页>牛牛的组队竞赛
牛牛的组队竞赛
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;
}
边栏推荐
- Excel快速跨表复制粘贴
- Processes and threads
- Arctangent entropy: the latest SCI paper in July 2022
- The excel table is transferred to word, and the table does not exceed the edge paper range
- DS90UB949
- Slam mapping and autonomous navigation simulation based on turnlebot3
- 一文搞懂Go语言Context
- R语言使用gridExtra包的grid.arrange函数将lattice包的多个可视化图像横向组合起来,ncol参数自定义组合图列数、nrow参数自定义组合图行数
- How to mix embedded MCU, arm and DSP?
- 同事写了一个责任链模式,bug无数...
猜你喜欢
The excel table is transferred to word, and the table does not exceed the edge paper range
After watching the video, AI model learned to play my world: cutting trees, making boxes, making stone picks, everything is good
Intel 13th generation core flagship exposure, single core 5.5ghz
(database authorization - redis) summary of unauthorized access vulnerabilities in redis
2022年湖南工学院ACM集训第二次周测题解
Visual Studio 2022下载及配置OpenCV4.5.5
Numpy np. Max and np Maximum implements the relu function
AI模型看看视频,就学会了玩《我的世界》:砍树、造箱子、制作石镐样样不差...
AOSP ~ NTP ( 网络时间协议 )
Processes and threads
随机推荐
解决msvcp120d.dll和msvcr120d.dll缺失
Incremental database backup - DB incr DB full
Key switch: press FN when pressing F1-F12
The tutor put forward 20 pieces of advice to help graduate students successfully complete their studies: first, don't plan to take a vacation
Driver development based on I2C protocol
R language uses grid of gridextra package The array function combines multiple visual images of the ggplot2 package horizontally, and the ncol parameter defines the number of columns of the combined g
Mysql根据时间搜索常用方法整理
Kibana~Kibana的安装和配置
MATLAB extrait les données numériques d'un fichier txt irrégulier (simple et pratique)
Internet socket (non) blocking write/read n bytes
How to clean up v$rman_ backup_ job_ Details view reports error ora-02030
多维度监控:智能监控的数据基础
Modular programming of single chip microcomputer
Stm32hal library upgrades firmware based on flash analog U disk (detailed explanation)
Spl06-007 air pressure sensor (example of barometer)
ORACLE进阶(一) 通过EXPDP IMPDP命令实现导dmp
[vtk] source code interpretation of vtkpolydatatoimagestencil
Machine learning 3.2 decision tree model learning notes (to be supplemented)
2022年中南大学夏令营面试经验
同事写了一个责任链模式,bug无数...