当前位置:网站首页>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;
}
边栏推荐
- Concurrent programming - singleton
- Visual Studio 2022下载及配置OpenCV4.5.5
- Web安全总结
- 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
- 聊聊Flink框架中的状态管理机制
- 剑指offer专项32-96题做题笔记
- This article explains the complex relationship between MCU, arm, MCU, DSP, FPGA and embedded system
- R语言使用data.table包进行数据聚合统计计算滑动窗口统计值(Window Statistics)、计算滑动分组中位数(median)并合并生成的统计数据到原数据集中
- After watching the video, AI model learned to play my world: cutting trees, making boxes, making stone picks, everything is good
- The uniapp scroll view solves the problems of high adaptability and bullet frame rolling penetration.
猜你喜欢

How to get started embedded future development direction of embedded

rxjs Observable filter Operator 的实现原理介绍

同事写了一个责任链模式,bug无数...

How should intermediate software designers prepare for the soft test

The excel table is transferred to word, and the table does not exceed the edge paper range

cgroup简介

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

Ripper of vulnhub

836. 合并集合(DAY 63)并查集

2022 northeast four provinces match VP record / supplementary questions
随机推荐
STL教程9-容器元素深拷贝和浅拷贝问题
DNS多点部署IP Anycast+BGP实战分析
Numpy np.max和np.maximum实现relu函数
. \vmware-vdiskmanager. exe -k “c:\\xxxxx.vmdk”
Linear table sequence table comprehensive application problem p18
2022 东北四省赛 VP记录/补题
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模型
Program process management tool -go Supervisor
How PHP solves the problem of high concurrency
CSRF
简单工厂和工厂方法模式
Ripper of vulnhub
MySQL union和union all区别
Kubernetes 三打探针及探针方式
How should intermediate software designers prepare for the soft test
PHP Basics
R语言使用gridExtra包的grid.arrange函数将ggplot2包的多个可视化图像横向组合起来,ncol参数自定义组合图列数、nrow参数自定义组合图行数
Xml的(DTD,xml解析,xml建模)