AtCoder Grand Contest 012 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 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:
N
a1 a2 … a3N
Output
Print the answer.
Sample Input 1
2
5 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
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
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(贪心)的更多相关文章
- AtCoder Grand Contest 012
AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...
- AtCoder Grand Contest 012 A
A - AtCoder Group Contest Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statem ...
- AtCoder Grand Contest 011
AtCoder Grand Contest 011 upd:这篇咕了好久,前面几题是三周以前写的... AtCoder Grand Contest 011 A - Airport Bus 翻译 有\( ...
- AtCoder Grand Contest 031 简要题解
AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\). ...
- AtCoder Grand Contest 010
AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题 ...
- AtCoder Grand Contest 009
AtCoder Grand Contest 009 A - Multiple Array 翻译 见洛谷 题解 从后往前考虑. #include<iostream> #include< ...
- AtCoder Grand Contest 008
AtCoder Grand Contest 008 A - Simple Calculator 翻译 有一个计算器,上面有一个显示按钮和两个其他的按钮.初始时,计算器上显示的数字是\(x\),现在想把 ...
- AtCoder Grand Contest 007
AtCoder Grand Contest 007 A - Shik and Stone 翻译 见洛谷 题解 傻逼玩意 #include<cstdio> int n,m,tot;char ...
- AtCoder Grand Contest 006
AtCoder Grand Contest 006 吐槽 这套题要改个名字,叫神仙结论题大赛 A - Prefix and Suffix 翻译 给定两个串,求满足前缀是\(S\),后缀是\(T\),并 ...
随机推荐
- poj2236Wireless Network
Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have ...
- SEC2- - mysql 的介绍
一.mysql的背景 前身属于瑞典的一家公司,mysql AB 08年被sun公司收购 09年被oracle公司收购 二.mysql的优点 1. 开源免费成本低 2. 性能高,移植性好 3. 体积 ...
- out.write()和out.print()区别,jsp注释区别
out.write()和out.print()结果一样,都是输出内容 前者输出html内容 后者输出变量 5 JSP注释 我们现在已经知道JSP是需要先编译成.java,再编译成.class的.其中& ...
- Netty之大名鼎鼎的EventLoop
EventLoopGroup 与Reactor: 前面的章节中我们已经知道了,一个Netty 程序启动时,至少要指定一个EventLoopGroup(如果使用到的是NIO,通常是指NioEventLo ...
- JS原型链详解
最近面试被问到了就决定好好深入理解原型链 对象 要清楚原型链,首先要弄清楚对象: 普通对象 最普通的对象:有__proto__属性(指向其原型链),没有prototype属性. 原型对象(person ...
- Android超简单气泡效果
阿里P7移动互联网架构师进阶视频(每日更新中)免费学习请点击:https://space.bilibili.com/474380680最近有用到水下气泡上升效果,因此在网上查了一下资料,结果还真找到了 ...
- Codeforces Round #535 E2-Array and Segments (Hard version)
Codeforces Round #535 E2-Array and Segments (Hard version) 题意: 给你一个数列和一些区间,让你选择一些区间(选择的区间中的数都减一), 求最 ...
- python学习第二十九天函数局部变量如何改变外部变量
python函数局部变量如何改变外部变量,之前我说过,局部变量是没办法改变外部变量的,除非局部变量找不到,去外部找,输出变量,使用关键词global 使变量改变外部变量. 1,使用关键词global ...
- React(5) --绑定函数事件
绑定函数事件 在以类继承的方式定义的组件中,为了能方便地调用当前组件的其他成员方法或属性(如:this.state),通常需要将事件处理函数运行时的 this 指向当前组件实例. run(){ ...
- CSAW CTF Qualification Round 2018 - shell->code
原题 Linked lists are great! They let you chain pieces of data together. nc pwn.chal.csaw.io 9005 链接:h ...