当前位置:网站首页>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;
}
边栏推荐
- Spl06-007 air pressure sensor (example of barometer)
- 小鹏 P7 撞护栏安全气囊未弹出,官方回应称撞击力度未达到弹出要求
- DNS多点部署IP Anycast+BGP实战分析
- POI excel cell wrap
- 抓包整理外篇fiddler———— 会话栏与过滤器[二]
- 2022 northeast four provinces match VP record / supplementary questions
- Asyncio warning deprecationwarning: there is no current event loop
- vulnhub之tomato(西红柿)
- PHP server interacts with redis with a large number of close_ Wait analysis
- PHP Basics
猜你喜欢
Excel quick cross table copy and paste
Numpy np. Max and np Maximum implements the relu function
小鹏 P7 撞护栏安全气囊未弹出,官方回应称撞击力度未达到弹出要求
Viewing binary bin files with notepad++ editor
STL tutorial 10 container commonalities and usage scenarios
vulnhub之momentum
Understand go language context in one article
PHP基础
MCDF实验1
The world's most popular font editor FontCreator tool
随机推荐
Notes on 32-96 questions of sword finger offer
Kibana~Kibana的安装和配置
Sheet1$.输出[Excel 源输出].列[XXX] 出错。返回的列状态是:“文本被截断,或者一个或多个字符在目标代码页中没有匹配项。”。
vulnhub之Ripper
Uniapp implementation Click to load more
STL Tutorial 9 deep copy and shallow copy of container elements
Go语言实现静态服务器
Hongmeng third training (project training)
CSRF
The excel table is transferred to word, and the table does not exceed the edge paper range
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
Excel表格转到Word中,表格不超边缘纸张范围
Use typora to draw flow chart, sequence diagram, sequence diagram, Gantt chart, etc. for detailed explanation
错排问题 (抽奖,发邮件)
cgroup简介
Analysis of EPS electric steering system
Asyncio warning deprecationwarning: there is no current event loop
抓包整理外篇fiddler———— 会话栏与过滤器[二]
(database authorization - redis) summary of unauthorized access vulnerabilities in redis
R语言使用gridExtra包的grid.arrange函数将ggplot2包的多个可视化图像横向组合起来,ncol参数自定义组合图列数、nrow参数自定义组合图行数