AtCoder:AtCoder Group Contest(思维)

A - AtCoder Group Contest


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

  • 1N105
  • 1ai109
  • 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.

题意:给出3*n个数,要求将他们分成n组,每组对答案贡献值为它们的中位数,问怎样分配使得中位数的和最大,输出最大值。

思路:先对数由小到大排序,显然最优解选择的中位数是3n-1,3n-3,3n-5......加起来就行。

# include <iostream>
# include <cstdio>
# include <algorithm>
using namespace std;

int a[300003];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0; i<3*n; ++i)
        scanf("%d",&a[i]);
    sort(a, a+3*n, greater<int>());
    long long sum = 0;
    for(int i=1, j=0; j<n; i+=2)
        sum += a[i], ++j;
    printf("%lld\n",sum);
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值