Urbanization
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are n people who plan to move to the cities. The wealth of the i of them is equal to ai. Authorities plan to build two cities, first for n1 people and second for n2 people. Of course, each of n candidates can settle in only one of the cities. Thus, first some subset of candidates of size n1 settle in the first city and then some subset of size n2 is chosen among the remaining candidates and the move to the second city. All other candidates receive an official refuse and go back home.

To make the statistic of local region look better in the eyes of their bosses, local authorities decided to pick subsets of candidates in such a way that the sum of arithmetic mean of wealth of people in each of the cities is as large as possible. Arithmetic mean of wealth in one city is the sum of wealth ai among all its residents divided by the number of them (n1 or n2 depending on the city). The division should be done in real numbers without any rounding.

Please, help authorities find the optimal way to pick residents for two cities.

Input

The first line of the input contains three integers nn1 and n2 (1 ≤ n, n1, n2 ≤ 100 000, n1 + n2 ≤ n) — the number of candidates who want to move to the cities, the planned number of residents of the first city and the planned number of residents of the second city.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 100 000), the i-th of them is equal to the wealth of the i-th candidate.

Output

Print one real value — the maximum possible sum of arithmetic means of wealth of cities' residents. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .

Examples
input
2 1 1
1 5
output
6.00000000
input
4 2 1
1 4 2 3
output
6.50000000
Note

In the first sample, one of the optimal solutions is to move candidate 1 to the first city and candidate 2 to the second.

In the second sample, the optimal solution is to pick candidates 3 and 4 for the first city, and candidate 2 for the second one. Thus we obtain (a3 + a4) / 2 + a2 = (3 + 2) / 2 + 4 = 6.5

分析:给你一堆数,取两堆,分别为n1,n2个,问平均数的和最大是多少?

   贪心,写出表达式发现从最大的开始取n1(n1<n2)个,然后取n2个;

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=(int)m;i<=(int)n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
const int maxn=1e5+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
inline ll read()
{
ll x=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,k,t,n1,n2;
double ans;
ll a[maxn],b,c;
int main()
{
int i,j;
scanf("%d%d%d",&n,&n1,&n2);
rep(i,,n)scanf("%lld",&a[i]);
sort(a+,a+n+);
if(n1<n2)swap(n1,n2);
for(i=n;i>=n+-n2;i--)b+=a[i];
for(i=n-n2;i>=n-n1-n2+;i--)c+=a[i];
printf("%.10f\n",(double)(n1*b+n2*c)/((ll)n1*n2));
//system("Pause");
return ;
}

Urbanization的更多相关文章

  1. Codeforces Round #382 (Div. 2)B. Urbanization 贪心

    B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a l ...

  2. Codeforces 735B - Urbanization

    735B - Urbanization 思路:贪心.人数少的城市住钱最多的那几个人. 不证明了,举个例子吧:a1<a2<a3<a4<a5 (a1+a2+a3)/3+(a4+a5 ...

  3. Codeforces735B Urbanization 2016-12-13 11:58 114人阅读 评论(0) 收藏

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

  4. 【50.88%】【Codeforces round 382B】Urbanization

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. Codeforces Round #382 (Div. 2) 继续python作死 含树形DP

    A - Ostap and Grasshopper zz题能不能跳到  每次只能跳K步 不能跳到# 问能不能T-G  随便跳跳就可以了  第一次居然跳越界0.0  傻子哦  WA1 n,k = map ...

  6. 每日英语:Dashing the China Dream

    Much has been said about what the 'China Dream' really means to many Chinese -- whether it is nation ...

  7. 城市边界线预测(根据灯光指数)(PUL)

    1.EXEALL.m function EXEALL(FilePath, FileName)%执行所有流程% FilePath: 文件夹所在路径% FileName: 文件夹名称 FullPath = ...

  8. 每日英语:China's Bad Earth

    In Dapu, a rain-drenched rural outpost in the heart of China's grain basket, a farmer grows crops th ...

  9. 每日英语:Now on Taobao: Outsourced Care for Grandma

    China's newly revised elder-care law has come as good news for a handful of entrepreneurs who specia ...

随机推荐

  1. [Q]复制授权了文件但仍显示“未注册”问题(安装在非默认目录或目录包含中文)

    1. 注意要将解压后的文件复制到CAD批量打图精灵安装目录,而不要复制文件夹,复制是提示是否需要覆盖,要选择覆盖. 2. 若通过第1步操作仍然显示“未注册”,则可能是由于安装目录含有中文或者不是默认目 ...

  2. Struts2的通配符配置方式

    Struts2的Action类很有意思,你可以使用3种方式来实现具体的Action类: 让你的Action类继承自ActionSupport类(项目中最常用这种方式,因为ActionSupport类中 ...

  3. Openjudge-NOI题库-变幻的矩阵

     题目描述 Description 有一个N x N(N为奇数,且1 <= N <= 10)的矩阵,矩阵中的元素都是字符.这个矩阵可能会按照如下的几种变幻法则之一进行变幻(只会变幻一次). ...

  4. UltimateDefrag磁盘碎片整理软件 v3.0.100.19汉化版

    软件名称:UltimateDefrag磁盘碎片整理软件 v3.0.100.19汉化版软件类别:汉化软件运行环境:Windows软件语言:简体中文授权方式:免费版软件大小:3.25 MB软件等级:整理时 ...

  5. 关于ajax跨域问题

    什么是跨域 1.document.domain+iframe的设置 2.动态创建script 3.利用iframe和location.hash 4.window.name实现的跨域数据传输 5.使用H ...

  6. vs2010帮助文档下载以及帮助查看器(H3Viewer)的使用

    在工作中遇到想查看vs2010的帮助文档.推荐使用H3Viewer.一个第三方的免费软件,独立于VS2010运行的帮助查看器.这方面的资料并不多.把本次自己使用的心得分享给大家. H3Viewer官方 ...

  7. [笔记]The Linux command line

    Notes on The Linux Command Line (by W. E. Shotts Jr.) edited by Gopher 感觉博客园是不是搞了什么CSS在里头--在博客园显示效果挺 ...

  8. 关于微信端不支持window.location.reload()

    今天写了一个调查问卷页面,项目经理说要表单提交之后页面刷新,之间没沟通清楚,以为整个页面重载,所以刚开始就用了window.location.reload()的方法. 但是发现,在微信直接打开之后,居 ...

  9. 4.当接口的请求方式为 application/json的时候时

    1..当接口的请求方式为 application/json的时候时,使用抓包软件(fiddler)获取到这个接口, 其中的Inspectprs-TextView中的内容就是jmeter中Body Da ...

  10. hadoop参数配置

    Hadoop参数汇总 linux参数 JVM参数 Hadoop参数大全 core-default.xml hdfs-default.xml yarn-default.xml Hadoop参数汇总 @( ...