当前位置:网站首页>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;
}
边栏推荐
- DS90UB949
- Spl06-007 air pressure sensor (example of barometer)
- R语言ggplot2可视化:gganimate包创建动态折线图动画(gif)、使用transition_reveal函数在动画中沿给定维度逐步显示数据、在折线移动方向添加数据点
- Linear table sequence table comprehensive application problem p18
- AOSP ~ NTP ( 网络时间协议 )
- ORACLE进阶(一) 通过EXPDP IMPDP命令实现导dmp
- previous permutation lintcode51
- 错排问题 (抽奖,发邮件)
- MySQL union和union all区别
- vulnhub之tomato(西红柿)
猜你喜欢

基于turtlebot3实现SLAM建图及自主导航仿真
![抓包整理外篇fiddler———— 会话栏与过滤器[二]](/img/04/e9cc027d753e7049f273d866eefdce.png)
抓包整理外篇fiddler———— 会话栏与过滤器[二]

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

Unity3D学习笔记5——创建子Mesh

STL教程10-容器共性和使用场景

解决msvcp120d.dll和msvcr120d.dll缺失

After using the thread pool for so long, do you really know how to reasonably configure the number of threads?

导师对帮助研究生顺利完成学业提出了20条劝告:第一,不要有度假休息的打算.....

vulnhub之Ripper

Visual Studio 2022下载及配置OpenCV4.5.5
随机推荐
DS90UB949
并发编程-单例
STL tutorial 8-map
Kibana - installation and configuration of kibana
libvirt 中体验容器
Viewing binary bin files with notepad++ editor
Concurrent programming - singleton
Uniapp implementation Click to load more
Understand go language context in one article
《剑指offer 04》二维数组查找
《剑指offer 03》数组中重复的数字
MCDF实验1
Keepalived中Master和Backup角色选举策略
STL Tutorial 9 deep copy and shallow copy of container elements
This article explains the complex relationship between MCU, arm, MCU, DSP, FPGA and embedded system
How to make others fear you
vulnhub之Ripper
Modular programming of single chip microcomputer
Mmc5603nj geomagnetic sensor (Compass example)
Asyncio warning deprecationwarning: there is no current event loop