# 8VC Venture Cup 2016 - Elimination Round E. Simple Skewness（枚举+三分）★

#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define L(i) i<<1
#define R(i) i<<1|1
#define INF  0x3f3f3f3f
#define pi acos(-1.0)
#define eps 1e-9
#define maxn 1000100
#define MOD 1000000007

int n,m;
int a[maxn];
long long sum[maxn];

int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int t,C = 1;
//scanf("%d",&t);
while(scanf("%d",&n) != EOF)
{
for(int i = 1; i <= n; i++)
scanf("%d",&a[i]);
sort(a+1,a+n+1);
sum[0] = 0;
for(int i = 1; i <= n; i++)
sum[i] = sum[i-1] + a[i];
long long pos = 1,len = 0;
long long ans = 0;
for(int i = 2; i < n; i++)
{
long long l = 1, r = min(i-1, n - i);
long long mid, mmid;
for(int j = 1; j <= 100; j++)
{
mid = (2*l + r) / 3;
mmid = (l + 2*r + 2) / 3;
long long m1 = (sum[i] - sum[i-mid-1] + sum[n] - sum[n-mid]);
long long m2 = (sum[i] - sum[i-mmid-1] + sum[n] - sum[n-mmid]);
if(m2*(mid*2+1) <= m1*(mmid*2+1))
r = mmid - 1;
else
l = mid + 1;
}
double cur = (double)(sum[i] - sum[i-l-1] + sum[n] - sum[n-l]) - (2*l+1)*a[i];
if(ans*(2*l+1) < cur*(2*len+1))   //为了避免精度问题， 转化为整数比较
{
ans = cur;
len = l;
pos = i;
}
}
printf("%lld\n",len*2+1);
for(int i = pos - len; i <= pos; i++)
printf("%d ",a[i]);
for(int i = n-len+1; i <= n; i++)
printf("%d%c",a[i],i==n?'\n':' ');
}
return 0;
}


• 本文已收录于以下专栏：

## 8VC Venture Cup 2017 - Elimination Round E. PolandBall and White-Red graph【枚举思维】

E. PolandBall and White-Red graph time limit per test 2 seconds memory limit per test 256 me...

## 8VC Venture Cup 2016 - Elimination Round-A. Robot Sequence（模拟）

A. Robot Sequence time limit per test 2 seconds memory limit per test 256 megabytes ...

## 8VC Venture Cup 2016 - Elimination Round A. Robot Sequence

A. Robot Sequence time limit per test 2 seconds memory limit per test 256 megabytes input standar...

## 8VC Venture Cup 2016 - Elimination Round总结

A题： A题题目链接 题目描述： A. Robot Sequence time limit per test 2 seconds memory limit pe...

## 8VC Venture Cup 2016 - Elimination Round C. Block Towers （二分）

C. Block Towers time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

## 8VC Venture Cup 2016 - Elimination Round B. Cards （隐式图DFS）

B. Cards time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

## 8VC Venture Cup 2016 - Elimination Round-B. Cards（暴力）

B. Cards time limit per test 2 seconds memory limit per test 256 megabytes input s...

## 8VC Venture Cup 2016 - Elimination Round-C. Block Towers（二分或暴力+数学）

C. Block Towers time limit per test 2 seconds memory limit per test 256 megabytes i...

举报原因： 您举报文章：8VC Venture Cup 2016 - Elimination Round E. Simple Skewness（枚举+三分）★ 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)