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. c#处理json格式类型的字符串

    string channelGroup=[{"SpType":"1","BaseInfoId":["xxx"," ...

  2. Django 无法通过request.POST.get()获取数据的问题

    原来是contentType为application/json时,Django不支持request.POST.get(),但可以通过request.body来获取string类型的参数: data = ...

  3. 解决Ubuntu12.04下rpcbind: cannot open '/var/run/rpcbind/rpcbind.xdr' file for reading

    不知道怎么回事,实验室的电脑在同学搞过之后,每次启动都报错 rpcbind: cannot open '/run/rpcbind/rpcbind.xdr' file for reading, errn ...

  4. vue 全局filter的坑

    下面连段代码的filter放在不同的位子会有不同的效果, 1.filter放在new vue之后,居然不起作用 <script> new Vue({ el: '#app', data: { ...

  5. jquery的扩展,及编辑插件的书写格式

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  6. springcloud费话之Eureka服务访问(restTemplate)

    目录: springcloud费话之Eureka基础 springcloud费话之Eureka集群 springcloud费话之Eureka服务访问(restTemplate) springcloud ...

  7. 用css画一个倒三角

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. postman 上一个接口的返回值作为下一个接口的入参

    在使用postman做接口测试的时候,在多个接口的测试中,如果需要上一个接口的返回值作为下一个接口的入参,其基本思路是: 1.获取上一个接口的返回值 2.将返回值设置成环境变量或者全局变量 3.设置下 ...

  9. 【记录】logstash 的filter 使用

    概述 logstash 之所以强大和流行,与其丰富的过滤器插件是分不开的 过滤器提供的并不单单是过滤的功能,还可以对进入过滤器的原始数据进行复杂的逻辑处理,甚至添加独特的新事件到后续流程中 强大的文本 ...

  10. shell PATH示例