当前位置:网站首页>牛牛的组队竞赛
牛牛的组队竞赛
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;
}
边栏推荐
猜你喜欢

AOSP ~ NTP ( 网络时间协议 )

Incremental database backup - DB incr DB full

ArcGIS应用(二十一)Arcmap删除图层指定要素的方法

DS90UB949

GCC compilation process and dynamic link library and static link library

MATLAB extrait les données numériques d'un fichier txt irrégulier (simple et pratique)

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

Xml的(DTD,xml解析,xml建模)

Kibana~Kibana的安装和配置

2022 东北四省赛 VP记录/补题
随机推荐
. \vmware-vdiskmanager. exe -k “c:\\xxxxx.vmdk”
Internet socket (non) blocking write/read n bytes
PHP Basics
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
How to: configure ClickOnce trust prompt behavior
R language uses the aggregate function to calculate the mean value (sum) of dataframe data grouping aggregation without setting na The result of RM calculation. If the group contains the missing value
Analysis of EPS electric steering system
Matlab extracts numerical data from irregular txt files (simple and practical)
软件测试周刊(第78期):你对未来越有信心,你对现在越有耐心。
同事写了一个责任链模式,bug无数...
并发编程-单例
mysql使用update联表更新的方法
鸿蒙第三次培训(项目实训)
R语言ggplot2可视化:gganimate包创建动态折线图动画(gif)、使用transition_reveal函数在动画中沿给定维度逐步显示数据、在折线移动方向添加数据点
Based on MCU, how to realize OTA differential upgrade with zero code and no development?
ASP.NET-酒店管理系統
银泰百货点燃城市“夜经济”
STL教程10-容器共性和使用场景
Event preview | the live broadcast industry "rolled in" to drive new data growth points with product power
R语言使用data.table包进行数据聚合统计计算滑动窗口统计值(Window Statistics)、计算滑动分组中位数(median)并合并生成的统计数据到原数据集中