当前位置:网站首页>Niuniu's team competition
Niuniu's team competition
2022-07-03 11:49:00 【Xiao Xing who likes to knock code~】
【 subject 】
【 Team competition 】
Niuniu held a programming competition , The participants in the competition are 3*n A contestant , Each player has a level value a_i. Now we're going to group these players , It consists of n A team , That is, each team 3 people . Niuniu found The level value of the team is equal to the second highest level value among the team members .
for example : The level values of three members of a team are 3,3,3. So the level of the team is 3 The level values of three members of a team are 3,2,3. So the level of the team is 3 The level values of three members of a team are 1,5,2. So the level of the team is 2 In order to make the game more interesting , Niuniu wants to arrange teams to maximize the sum of level values of all teams . As the example shows : If Niuniu put 6 Two players are divided into two teams , If the scheme is : team1:{1,2,5}, team2:{5,5,8}, At this time, the sum of the horizontal values is 7. And if the plan is : team1:{2,5,8}, team2:{1,5,5}, At this time, the sum of the horizontal values is 10. There is nothing like the sum of 10 A bigger plan , So the output 10.
Input description :
The first line of input is a positive integer n(1 ≤ n ≤ 10^5) The second line includes 3*n It's an integer a_i(1 ≤ a_i ≤ 10^9), Represents the level value of each contestant .
Output description :
Output an integer representing the sum of the level values of all teams, the maximum value .
Example 1:
Input :
2
5 2 8 5 1 5
Output :
10
【 Ideas 】
Rank all horizontal values in descending order first , Then take two numbers from the first position , These two numbers are respectively the highest level and the middle level in a group , Total n Group .

【 Code 】
#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
- R language ggplot2 visualization: gganimate package creates dynamic line graph animation (GIF) and uses transition_ The reveal function displays data step by step along a given dimension in the animat
- Visual Studio 2022下载及配置OpenCV4.5.5
- 小鹏 P7 撞护栏安全气囊未弹出,官方回应称撞击力度未达到弹出要求
- C language utf8toutf16 (UTF-8 characters are converted to hexadecimal encoding)
- uniapp scroll view 解决高度自适应、弹框滚动穿透等问题。
- Analysis of EPS electric steering system
- STL Tutorial 9 deep copy and shallow copy of container elements
- Redis things
- vulnhub之cereal
猜你喜欢

Ripper of vulnhub

Web security summary

vulnhub之pyexp

金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~

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

AI模型看看视频,就学会了玩《我的世界》:砍树、造箱子、制作石镐样样不差...

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

vulnhub之tomato(西红柿)

鸿蒙第三次培训(项目实训)

软件测试周刊(第78期):你对未来越有信心,你对现在越有耐心。
随机推荐
同事写了一个责任链模式,bug无数...
MCDF实验1
Visual Studio 2022下载及配置OpenCV4.5.5
MySQL union和union all区别
STL Tutorial 9 deep copy and shallow copy of container elements
Multi dimensional monitoring: the data base of intelligent monitoring
R语言ggplot2可视化:gganimate包创建动态折线图动画(gif)、使用transition_reveal函数在动画中沿给定维度逐步显示数据、在折线移动方向添加数据点
AOSP ~ NTP ( 网络时间协议 )
软件测试周刊(第78期):你对未来越有信心,你对现在越有耐心。
The R language uses the hist function in the native package (basic import package, graphics) to visualize the histogram plot
聊聊Flink框架中的状态管理机制
牛牛的组队竞赛
Kibana~Kibana的安装和配置
DS90UB949
Analysis of EPS electric steering system
POI excel cell wrap
优化接口性能
【学习笔记】dp 状态与转移
libvirt 中体验容器
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