AtCoder Grand Contest 012 A
来源:互联网 发布:u盘数据恢复公司 编辑:程序博客网 时间:2024/06/04 19:01
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 1, 5, 2 has a strength 2, and a team of three participants of strength 3, 2, 3 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:
Na1 a2 … a3N
Output
Print the answer.
Sample Input 1
25 2 8 5 1 5
Sample Output 1
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
101000000000 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
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 Grand Contest 017-A
- AtCoder Grand Contest 018 A
- atcoder grand Contest 018 A
- AtCoder Grand Contest 018 A
- AtCoder Grand Contest 012 B
- AtCoder Grand Contest 012 题解
- Atcoder Grand Contest 012 B
- AtCoder Grand Contest 017-A Biscuits
- AtCoder Grand Contest 010
- AtCoder Grand Contest 011
- AtCoder Grand Contest 018
- AtCoder Grand Contest 018
- Atcoder Grand Contest 019
- AtCoder Grand Contest 010
- AtCoder Grand Contest 008
- AtCoder Grand Contest 005【A栈模拟,B单调栈】
- AtCoder Grand Contest 011 A\B 贪心、二分
- 模仿tmall 小猫咪的耳朵
- 反射之前奏Oracle升级版
- 5.new和delete
- os 模块
- MySQL学习笔记2.0
- AtCoder Grand Contest 012 A
- iptables学习记录
- 6.引用
- 任务八:响应式网格(栅格化)布局
- 7.函数的默认值
- 8.函数重载及其优先级
- 引用的全面理解
- 9.函数模板
- 10.CV限定符