当前位置:网站首页>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;
}
边栏推荐
- 【学习笔记】dp 状态与转移
- Raven2 of vulnhub
- Slam mapping and autonomous navigation simulation based on turnlebot3
- uniapp实现点击加载更多
- Dynamic programming (interval DP)
- The uniapp scroll view solves the problems of high adaptability and bullet frame rolling penetration.
- Capturing and sorting out external Fiddler -- Conversation bar and filter [2]
- 并发编程-单例
- Viewing binary bin files with notepad++ editor
- vulnhub之pyexp
猜你喜欢
Based on MCU, how to realize OTA differential upgrade with zero code and no development?
PHP基础
Excel quick cross table copy and paste
Spl06-007 air pressure sensor (example of barometer)
vulnhub之GeminiInc
PHP server interacts with redis with a large number of close_ Wait analysis
Gut | Yu Jun group of the Chinese University of Hong Kong revealed that smoking changes intestinal flora and promotes colorectal cancer (do not smoke)
Yintai department store ignites the city's "night economy"
《剑指offer 04》二维数组查找
ASP.NET-酒店管理系統
随机推荐
C language utf8toutf16 (UTF-8 characters are converted to hexadecimal encoding)
Capturing and sorting out external Fiddler -- Conversation bar and filter [2]
Phpcms prompt message page Jump to showmessage
Slam mapping and autonomous navigation simulation based on turnlebot3
MySQL union和union all区别
抓包整理外篇fiddler———— 会话栏与过滤器[二]
并发编程-单例
软件测试周刊(第78期):你对未来越有信心,你对现在越有耐心。
MySQL searches and sorts out common methods according to time
Raven2 of vulnhub
鸿蒙第四次培训
GCC compilation process and dynamic link library and static link library
Arctangent entropy: the latest SCI paper in July 2022
【学习笔记】dp 状态与转移
Mmc5603nj geomagnetic sensor (Compass example)
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
解决msvcp120d.dll和msvcr120d.dll缺失
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
Qt+VTK+OCCT读取IGES/STEP模型
优化接口性能