Time limit : 2sec / Memory limit : 256MB

Score : 300 points

Problem Statement

There are 3N participants in AtCoder Group Contest. The strength of the i-th participant is represented by an integer ai. They will form N teams, each consisting of three participants. No participant may belong to multiple teams.

The strength of a team is defined as the second largest strength among its members. For example, a team of participants of strength 152 has a strength 2, and a team of three participants of strength 323 has a strength 3.

Find the maximum possible sum of the strengths of N teams.

Constraints

  • 1≤N≤105
  • 1≤ai≤109
  • ai are integers.

Input

Input is given from Standard Input in the following format:

N
a1 a2 a3N

Output

Print the answer.


Sample Input 1

Copy
2
5 2 8 5 1 5

Sample Output 1

Copy
10

The following is one formation of teams that maximizes the sum of the strengths of teams:

  • Team 1: consists of the first, fourth and fifth participants.
  • Team 2: consists of the second, third and sixth participants.

Sample Input 2

Copy
10
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

Sample Output 2

Copy
10000000000

The sum of the strengths can be quite large.

****************************************************************************************************************************************************

题意:给你3N个数,要你组成N只team,每一只team3人 :D

每一只team的值为3人的中间值。求出每一只对的总值。

解题思路:先sort一下。可以得到 a1, a2, a3 ~~~~ aN aN+1 ~~~~ a2N a2N+1 ~~~~~a3N;

要求和最大, 所以中间那个要最大,a1, a3N, a3N-1 组成一组

很容易就可以知道贪心的策略了。

****************************************************************************************************************************************************

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long LL;
const int maxn = 300000+10;
int a[maxn];
int main()
{
ios::sync_with_stdio(0);
int N;
cin >> N;
for(int i=0;i<3*N;i++) cin >> a[i];
sort(a, a+3*N);
LL ans = 0;
int j=3*N - 2;
for(int i=1;i<=N;i++)
{
ans += a[j];
j-=2;
}
cout << ans << endl;
return 0;
}

AtCoder Grand Contest 012 A - AtCoder Group Contest(贪心)的更多相关文章

  1. AtCoder Grand Contest 012

    AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...

  2. AtCoder Grand Contest 012 A

    A - AtCoder Group Contest Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statem ...

  3. AtCoder Grand Contest 011

    AtCoder Grand Contest 011 upd:这篇咕了好久,前面几题是三周以前写的... AtCoder Grand Contest 011 A - Airport Bus 翻译 有\( ...

  4. AtCoder Grand Contest 031 简要题解

    AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\). ...

  5. AtCoder Grand Contest 010

    AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题 ...

  6. AtCoder Grand Contest 009

    AtCoder Grand Contest 009 A - Multiple Array 翻译 见洛谷 题解 从后往前考虑. #include<iostream> #include< ...

  7. AtCoder Grand Contest 008

    AtCoder Grand Contest 008 A - Simple Calculator 翻译 有一个计算器,上面有一个显示按钮和两个其他的按钮.初始时,计算器上显示的数字是\(x\),现在想把 ...

  8. AtCoder Grand Contest 007

    AtCoder Grand Contest 007 A - Shik and Stone 翻译 见洛谷 题解 傻逼玩意 #include<cstdio> int n,m,tot;char ...

  9. AtCoder Grand Contest 006

    AtCoder Grand Contest 006 吐槽 这套题要改个名字,叫神仙结论题大赛 A - Prefix and Suffix 翻译 给定两个串,求满足前缀是\(S\),后缀是\(T\),并 ...

随机推荐

  1. 简单入门爬斗鱼颜值区妹子照片 v1.1

    这是个比较简单的入门爬虫.基于python3. urllib,urllib2,python3中用urllib.request代替,使用方法基本一致. #python3 import urllib.re ...

  2. MapReduce(2): How does Mapper work

    In the previous post, we've illustrated how Hadoop MapReduce prepares input for Mappers. Long story ...

  3. Convolutional Neural Networks(2):Sparse Interactions, Receptive Field and Parameter Sharing

    Sparse Interactions, Receptive Field and Parameter Sharing是整个CNN深度网络的核心部分,我们用本文来具体分析其原理. 首先我们考虑Feedf ...

  4. oracle函数与存储方法

    oracle中的函数, 可以理解为java中的方法 有参数, 或者没有参数 通过return返回一个值 oracle存储过程跟函数唯一的区别, 存储过程不能通过return返回一个值 参数的类型, i ...

  5. C++学习笔记(二)--基础

    1.浮点型数值不管写成什么样 都是以指数形式保存在内存中 数符|数字部分|指数部分 例:+0.33E10 数字部分的整数部分不能大于1,小数点后面不能是0. 2.字符数据是以整数形式保存在内存中的(A ...

  6. 《剑指offer》面试题10 二进制中1的个数 Java版

    书中方法一:对于每一位,用1求与,如果为1表明该位为1.一共要进行32次,int4字节32位. public int check(int a){ int result = 0; int judge = ...

  7. python学习第三十一天函数的嵌套及函数的作用域

    python函数的嵌套是指在函数里面嵌套另外一个函数,可以嵌套更多,函数一旦套用了另外一个函数,他的作用域就已经形成,可以通过global关键词改变变量的作用域,下面详细说明函数的嵌套及函数的作用域 ...

  8. raw, SOCK_RAW - Linux IPv4 raw socket.

    总 览 #include <sys/socket.h> #include <netinet/in.h> raw_socket = socket(PF_INET, SOCK_RA ...

  9. vue不是内部或外部命令的解决方法

    1.在nodejs的安装目录下,找到vue.cmd,将此路径加到环境变量中,我是通过nvm管理node版本的,路径是C:\Users\hy\AppData\Roaming\nvm\v6.10.0,关闭 ...

  10. 二、Ajax请求MVC中数据查询表返回datatable

    一.Ajax请求MVC中数据查询表返回datatable 解决方式 返回list