Urbanization
2 seconds
256 megabytes
standard input
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.
The first line of the input contains three integers n, n1 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.
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
.
2 1 1
1 5
6.00000000
4 2 1
1 4 2 3
6.50000000
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的更多相关文章
- Codeforces Round #382 (Div. 2)B. Urbanization 贪心
B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a l ...
- Codeforces 735B - Urbanization
735B - Urbanization 思路:贪心.人数少的城市住钱最多的那几个人. 不证明了,举个例子吧:a1<a2<a3<a4<a5 (a1+a2+a3)/3+(a4+a5 ...
- 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 ...
- 【50.88%】【Codeforces round 382B】Urbanization
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Codeforces Round #382 (Div. 2) 继续python作死 含树形DP
A - Ostap and Grasshopper zz题能不能跳到 每次只能跳K步 不能跳到# 问能不能T-G 随便跳跳就可以了 第一次居然跳越界0.0 傻子哦 WA1 n,k = map ...
- 每日英语:Dashing the China Dream
Much has been said about what the 'China Dream' really means to many Chinese -- whether it is nation ...
- 城市边界线预测(根据灯光指数)(PUL)
1.EXEALL.m function EXEALL(FilePath, FileName)%执行所有流程% FilePath: 文件夹所在路径% FileName: 文件夹名称 FullPath = ...
- 每日英语:China's Bad Earth
In Dapu, a rain-drenched rural outpost in the heart of China's grain basket, a farmer grows crops th ...
- 每日英语: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 ...
随机推荐
- PotPlayer播放器 莫尼卡汉化绿色版 V1.6.48089 32位
软件名称: PotPlayer播放器 莫尼卡汉化绿色版 软件语言: 简体中文 授权方式: 免费软件 运行环境: Win7 / Vista / Win2003 / WinXP 软件大小: 10.5MB ...
- maven发布本地包,eclipse-maven集成tomcat7热部署项目
国内maven 库 :http://maven.aliyun.com/nexus/content/groups/public/ maven安装不在中央仓库的jar包: mvn install:inst ...
- Hive 常用函数
参考地址:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF 1. parse_url(url, partToExt ...
- synchronized细节问题
一.synchronized有锁重入的特点,某个线程得到对象的锁后,再次请求此对象可以再次得到改对象的锁.如下示例,在method1中调用method2,在method2中调用method3,而met ...
- notepad++正则表达式替换字符串详解
正则表达式是一个查询的字符串,它包含一般的字符和一些特殊的字符,特殊字符可以扩展查找字符串的能力,正则表达式在查找和替换字符串的作用不可忽视,它 能很好提高工作效率. EditPlus的查找,替换,文 ...
- Ubuntu配置Samba
一.安装Ubuntu samba服务器 $ sudo apt-get install samba $ sudo apt-get install smbclient # Linux客户端测试用 二.创建 ...
- Linux下SVN的简单配置
1.安装svn sudo yum install subversion 2.查看是否安装成功 svnserve --version 3.创建svn目录 svnadmin create 目录名 例如:s ...
- 【转】使用sinopia五步快速完成本地npm搭建
使用sinopia五步快速完成本地npm搭建 时间 2016-03-01 14:55:30 繁星UED 原文 http://ued.fanxing.com/shi-yong-sinopiawu-b ...
- 转:LoadRunner响应时间与用户体验时间不一致问题的深入分析
在新一代一期项目非功能测试过程中,我们发现了LoadRunner测试响应时间与客户端实际用户体验时间不一致的现象.例如员工渠道上线后,客户体验时间远远超过了LoadRunner测试响应时间.本文针对这 ...
- 第八十三节,CSS3动画效果
CSS3动画效果 学习要点: 1.动画简介 2.属性详解 3.简写和版本 本章主要探讨HTML5中CSS3的动画效果,可以通过类 Flash那样的关键帧模式控制运行. 一.动画简介 CSS3提 ...