• 给定一个序列A
• 选取一些数,使得这些数的平均数减中位数尽可能大
• 1 ≤ n ≤ 2 * 1e5
• 一定选择奇数个数。若选择偶数个数则可将中间两个数较大的一 个删除使得答案更优
• 枚举中位数 三分区间长度
• 排序 贪心计算平均数
枚举中位数 三分长度 整数三分要向上取整 真骚啊 这是一个凸函数
/*
if you can't see the repay
Why not just work step by step
rubbish is relaxed
to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod = (int)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);
/*namespace sgt
{
#define mid ((l+r)>>1)
#undef mid
}*/
const int MAX_N = 200025;
long long arr[MAX_N],sum[MAX_N];
int n;
int solve(int m1,int m2,int i)
{
ll s1 = sum[n] - sum[n-m1]+sum[i]-sum[i-m1-1];
ll s2 = sum[n] - sum[n-m2]+sum[i]-sum[i-m2-1];
return s1*(2*m2+1)<s2*(2*m1+1);
}
int main()
{
//ios::sync_with_stdio(false);
//freopen("a.txt","r",stdin);
//freopen("b.txt","w",stdout);
scanf("%d",&n);
for(int i = 1;i<=n;++i) scanf("%lld",&arr[i]);
sort(arr+1,arr+1+n);
for(int i = 1;i<=n;++i)
sum[i] = sum[i-1]+arr[i];
int ans_ = 1,x = 0;
ll maxx = 0;
for(int i = 2;i<=n-1;i++)
{
int l = 0,r = min(i-1,n-i);
while(l<=r)
{
int midl = (2*l+r)/3;
int midr = (2*r+l+2)/3; //向上取整
if(solve(midl,midr,i)) l = midl+1;
else r = midr-1;
}
ll tmp = sum[n] - sum[n-l] + sum[i] - sum[i-l-1]-arr[i]*(2*l+1);
if(tmp*(2*x+1)>maxx*(2*l+1))
{
maxx = tmp;
ans_ = i;
x = l;
}
}
printf("%d\n",x*2+1);
for(int i = ans_-x;i<=ans_;++i)
printf("%lld ",arr[i]);
for(int i = n-x+1;i<=n;++i)
i==n?printf("%lld\n",arr[i]):printf("%lld ",arr[i]);
//fclose(stdin);
//fclose(stdout);
//cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}