E. Simple Skewness

题目连接:

http://www.codeforces.com/contest/626/problem/E

Description

Define the simple skewness of a collection of numbers to be the collection's mean minus its median. You are given a list of n (not necessarily distinct) integers. Find the non-empty subset (with repetition) with the maximum simple skewness.

The mean of a collection is the average of its elements. The median of a collection is its middle element when all of its elements are sorted, or the average of its two middle elements if it has even size.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of elements in the list.

The second line contains n integers xi (0 ≤ xi ≤ 1 000 000) — the ith element of the list.

Output

In the first line, print a single integer k — the size of the subset.

In the second line, print k integers — the elements of the subset in any order.

If there are multiple optimal subsets, print any.

Sample Input

4

1 2 3 12

Sample Output

3

1 2 12

Hint

题意

给你n个数,然后让你选出某些数出来,使得你选出来的数的平均值减去中位数最大

题解:

暴力枚举中位数,然后二分长度

显然我们知道中位数是什么,长度是什么之后,我们直接取最大的mid个数就好了

从n开始取mid个,从中位数取mid个,这样的平均值最大嘛。

我们可以大胆猜想(不用证明),长度的那个曲线是一个单峰的,所以我们三分或者二分去做,都兹瓷。

然后这道题就完了。

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+7;
long long w[maxn],s[maxn];
int n;
long long get(int x,int i)
{
return s[x]-s[x-i-1]+s[n]-s[n-i];
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%lld",&w[i]);
sort(w+1,w+1+n);
for(int i=1;i<=n;i++)
s[i]+=w[i]+s[i-1];
int ans1=1,ans2=0;
double s1=0;
for(int i=2;i<=n;i++)
{
int l=2,r=min(n-i,i-1);
int tmp=1;
while(l<=r)
{
int mid=(l+r)/2;
if(get(i,mid-1)*(2*mid+1)<get(i,mid)*(2*mid-1))
{
tmp=mid;
l=mid+1;
}
else
r=mid-1;
}
double tmp2 = 1.0*get(i,tmp)/(1.0*2*tmp+1) - 1.0*w[i];
if(tmp2>s1)
{
s1=tmp2;
ans2=tmp,ans1=i;
}
}
printf("%d\n",ans2*2+1);
for(int i=ans1;i>ans1-ans2-1;i--)printf("%d ",w[i]);
for(int i=n;i>n-ans2;i--)printf("%d ",w[i]);
printf("\n");
}

8VC Venture Cup 2016 - Elimination Round E. Simple Skewness 暴力+二分的更多相关文章

  1. 8VC Venture Cup 2016 - Elimination Round A. Robot Sequence 暴力

    A. Robot Sequence 题目连接: http://www.codeforces.com/contest/626/problem/A Description Calvin the robot ...

  2. 8VC Venture Cup 2016 - Elimination Round

    在家补补题   模拟 A - Robot Sequence #include <bits/stdc++.h> char str[202]; void move(int &x, in ...

  3. 8VC Venture Cup 2016 - Elimination Round D. Jerry's Protest 暴力

    D. Jerry's Protest 题目连接: http://www.codeforces.com/contest/626/problem/D Description Andrew and Jerr ...

  4. 8VC Venture Cup 2016 - Elimination Round (C. Block Towers)

    题目链接:http://codeforces.com/contest/626/problem/C 题意就是给你n个分别拿着2的倍数积木的小朋友和m个分别拿着3的倍数积木的小朋友,每个小朋友拿着积木的数 ...

  5. codeforces 8VC Venture Cup 2016 - Elimination Round C. Lieges of Legendre

    C. Lieges of Legendre 题意:给n,m表示有n个为2的倍数,m个为3的倍数:问这n+m个数不重复时的最大值 最小为多少? 数据:(0 ≤ n, m ≤ 1 000 000, n + ...

  6. 8VC Venture Cup 2016 - Elimination Round F - Group Projects dp好题

    F - Group Projects 题目大意:给你n个物品, 每个物品有个权值ai, 把它们分成若干组, 总消耗为每组里的最大值减最小值之和. 问你一共有多少种分组方法. 思路:感觉刚看到的时候的想 ...

  7. 8VC Venture Cup 2016 - Elimination Round G. Raffles 线段树

    G. Raffles 题目连接: http://www.codeforces.com/contest/626/problem/G Description Johnny is at a carnival ...

  8. 8VC Venture Cup 2016 - Elimination Round F. Group Projects dp

    F. Group Projects 题目连接: http://www.codeforces.com/contest/626/problem/F Description There are n stud ...

  9. 8VC Venture Cup 2016 - Elimination Round C. Block Towers 二分

    C. Block Towers 题目连接: http://www.codeforces.com/contest/626/problem/C Description Students in a clas ...

随机推荐

  1. flask_返回字节流错误

    # flask_返回字节流错误 def export_data(filename, fields, data, names=None, sheet='Sheet1'): # fields 为list ...

  2. 004 ConcurrentHashMap原理

    下面这部分内容转载自: http://www.haogongju.net/art/2350374 JDK5中添加了新的concurrent包,相对同步容器而言,并发容器通过一些机制改进了并发性能.因为 ...

  3. C#杂七杂八记录

     1. 日期格式表示 DateTime.Now.ToString("yyyy-MM-dd")  2. div跟屏幕的高度一样高,自适应 <style> html, bo ...

  4. 流程控制--if条件

    /* if ....else .... */ [root@localhost test1]# vim .py //ADD #!/usr/bin/python >: print 'hello py ...

  5. LeetCode解题报告—— Linked List Cycle II & Reverse Words in a String & Fraction to Recurring Decimal

    1. Linked List Cycle II Given a linked list, return the node where the cycle begins. If there is no ...

  6. Maximum Subarray——经典

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...

  7. JSON优缺点

    总结: 1.占带宽小(格式是压缩的) 2. js通过eval()进行Json读取(便于客户端读取) 3. JSON支持多种语言(c.c++.PHP等),便于服务端解析 JSON (JavaScript ...

  8. jdk1.6错误:no such provider: BC jdk1.6支持SSL问题

    程序调用https请求,由于jdk1.6只支持1024的DH,需要调整 1.在$JAVA_HOME/jre/lib/ext 下添加加密组件包 bcprov-jdk15on-1.52.jar和bcpro ...

  9. 【剑指offer】面试题 57. 和为 S 的数字

    面试题 57. 和为 S 的两个数字 题目一:和为 S 的两个数字 题目 输入一个递增排序的数组和一个数字 S,在数组中查找两个数,是的他们的和正好是 S,如果有多对数字的和等于 S, 输出两个数的乘 ...

  10. 视频H5のVideo标签在微信里的坑和技巧

    随着 4G 的普遍以及 WiFi 的广泛使用,手机上的网速已经足够稳定和高速,以视频为主的 HTML5 也越来越普遍了,相比帧动画,视频的表现更加丰富,前段时间开发了一个以视频为主的移动端 HTML5 ...