B. Urbanization

题目链接

http://codeforces.com/contest/735/problem/B

题面

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

题意

一共有n个数,第i个数是a[i],现在你需要选出n1个数和n2个数,使得那n1个数的和除以n1加上n2个数的和除以n2的值最大。

题解

贪心,如果n1>n2,那么交换

然后选择最大的n1个数为n1集合,然后次大的n2个数为n2集合。

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
int n,n1,n2,nn1,nn2;
double a[maxn];
int main()
{
scanf("%d%d%d",&n,&n1,&n2);
if(n1>n2)swap(n1,n2);
nn1=n1,nn2=n2;
for(int i=0;i<n;i++)
scanf("%lf",&a[i]);
sort(a,a+n);
reverse(a,a+n);
double sum1=0,sum2=0;
for(int i=0;i<n;i++){
if(n1){
sum1+=a[i];
n1--;
}else if(n2){
sum2+=a[i];
n2--;
}
}
double ans = (sum1/nn1)+(sum2/nn2);
printf("%.12f\n",ans);
}

Codeforces Round #382 (Div. 2)B. Urbanization 贪心的更多相关文章

  1. Codeforces Round #202 (Div. 1) A. Mafia 贪心

    A. Mafia Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/348/problem/A D ...

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

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

  3. Codeforces Round #164 (Div. 2) E. Playlist 贪心+概率dp

    题目链接: http://codeforces.com/problemset/problem/268/E E. Playlist time limit per test 1 secondmemory ...

  4. Codeforces Round #180 (Div. 2) B. Sail 贪心

    B. Sail 题目连接: http://www.codeforces.com/contest/298/problem/B Description The polar bears are going ...

  5. Codeforces Round #192 (Div. 1) A. Purification 贪心

    A. Purification Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/probl ...

  6. Codeforces Round #274 (Div. 1) A. Exams 贪心

    A. Exams Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/A Des ...

  7. Codeforces Round #374 (Div. 2) B. Passwords 贪心

    B. Passwords 题目连接: http://codeforces.com/contest/721/problem/B Description Vanya is managed to enter ...

  8. Codeforces Round #303 (Div. 2) C. Woodcutters 贪心

    C. Woodcutters Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/545/probl ...

  9. Codeforces Round #377 (Div. 2) D. Exams 贪心 + 简单模拟

    http://codeforces.com/contest/732/problem/D 这题我发现很多人用二分答案,但是是不用的. 我们统计一个数值all表示要准备考试的所有日子和.+m(这些时间用来 ...

随机推荐

  1. yield学习续:yield return迭代块在Unity3D中的应用——协程

    必读好文推荐: Unity协程(Coroutine)原理深入剖析 Unity协程(Coroutine)原理深入剖析再续 上面的文章说得太透彻,所以这里就记一下自己的学习笔记了. 首先要说明的是,协程并 ...

  2. java8的接口新特性(可以有方法体的接口)(转)

    以前Java的接口中定义的方法不可以有方法体,这样试用起来,有时候听不方便的,当有多个类实现了想同的接口,接口中某一些方法的实现体可能都是一样的时候,这样无疑浪费了很多时间,在写重复的代码(或者说co ...

  3. Windows操作系统消费者价值亮点

    在讨论Windows操作系统之前,我们先看看消费者是什么. 消费者是产品和服务的最终使用者 ,其购买商品的目的主要是用于个人或家庭需要. 那么消费者的需求是什么,是使用,所以谁能给消费者更好的使用体验 ...

  4. 安装Pomelo 时遇到的坑

    一.Pomelo相关的代码地址 https://github.com/NetEase,这里面包含比较多的项目. 2. https://github.com/NetEase/pomelo/wiki/%E ...

  5. 不能运行,:framework not found SenTestingKit

    1. 真机调试,提示 ld: framework not found SenTestingKit $(DEVELOPER_LIBRARY_DIR)/Frameworks  

  6. IOS笔记之UIKit_UIScrollView

    //通过系统的一个接口 拿到是不是第一次启动这个程序 如果是就调用导航页 如果不是 直接进入下一个视图 NSUserDefaults *userDefaults = [NSUserDefaults s ...

  7. vpn与局域网冲突解决方案

    打开vpn后,所有通过网卡发出去的包都会走vpn,而不会走局域网,所以局域网无法访问,vpn为本机指定路由,让网卡把包发给vpn线路(比如10网段).如果为本机指定到达局域网的路由,访问局域网的包就知 ...

  8. Mozilla Firefox 24.0 Beta 5 发布

    Mozilla今天将Firefox 24.0 Beta 5版本放到了FTP的release目录,新版开始全面支持OS X 10.7全新的滚动条样式,禁止网站插件运行的功能出现在任务栏左侧,调整了界面U ...

  9. 用c#开发微信 (9) 微渠道 - 推广渠道管理系统 4 部署测试 (最终效果图)

    我们可以使用微信的“生成带参数二维码接口”和 “用户管理接口”,来实现生成能标识不同推广渠道的二维码,记录分配给不同推广渠道二维码被扫描的信息.这样就可以统计和分析不同推广渠道的推广效果. 本文是微渠 ...

  10. [openwrt 项目开发笔记]: 传送门

    “Openwrt 项目开发笔记”系列传送门: [Openwrt 项目开发笔记]:Openwrt平台搭建(一) (2014-07-11 00:11) [Openwrt 项目开发笔记]:Openwrt平台 ...