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 #459 (Div. 2) C 思维,贪心 D 记忆化dp

    Codeforces Round #459 (Div. 2) C. The Monster 题意:定义正确的括号串,是能够全部匹配的左右括号串. 给出一个字符串,有 (.). ? 三种字符, ? 可以 ...

  2. Codeforces Round #646 (Div. 2) E(贪心,bfs)

    Codeforces Round #646 (Div. 2) E 题目大意: 给一棵树,每个节点有三个权值 A,B,C, (B,C为0或1),每次你可以花费 A[u] *k的代价让A子树中的任意 k ...

  3. Codeforces Round #382 (Div. 2)C. Tennis Championship(贪心) D.巴赫猜想

    C: 题意:每个人输了比赛就会被淘汰,每两个人可以打比赛的要求是a赢过x场比赛b赢过y场比赛则当abs(x - y) <= 1 时他们可以进行比赛,总共n个选手,问最终的赢家可能赢过的场次的最大 ...

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

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

  5. Codeforces Round #579 (Div. 3) E. Boxers (贪心)

    题目链接:https://codeforces.com/contest/1203/problem/E 思路:一开始想的是记录数字出现次数,看每个数字的三种变化能否产生新数,但是这样容易多算或者少算答案 ...

  6. Codeforces Round #392(div 2) 758D (贪心)

    orz 最近被水题卡+FST,各种掉rating 题目大意 一个数s它是n进制的,但是每一位不是用'A','B'....表示的,而是用10,11等等表示的,将它还原成十进制 这种表示方法显然会产生多解 ...

  7. Codeforces Round #579 (Div. 3)--Boxers(贪心,排序)

    题目链接 题意: 给定n个质量为ai的盒子,每个盒子质量都可以改变不超过1的单位质量,求能够选出的互不相同的质量的盒子的最大数目. 题目条件: 1<=n<=150000,1<=ai& ...

  8. szu cf集训Codeforces Round #631 (Div. 2)A ~ D[贪心,数据结构,思维,dp]

    A. Dreamoon and Ranking Collection 题意:题意不太好理解.简单来讲就是,给出一组数,能从1最多数到几,不够的用数来填,最多填x次.思路:代码很简单-先出现过的地方肯定 ...

  9. Codeforces Round #382 (Div. 2) D. Taxes 歌德巴赫猜想

    题目链接:Taxes D. Taxes time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

最新文章

  1. RabbitMQ(二):RabbitMQ高级特性
  2. Golang 标准库log的实现
  3. Mac上解决Chrome浏览器跨域问题
  4. IE8“开发人员工具”(下)
  5. 1.c++模式设计-简单工厂模式
  6. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! node-sass@
  7. pat-A1043:Is it a Binary Search Tree(二叉搜索树和及其镜像树的遍历)
  8. 计算机病毒入侵计算机症状,win7系统电脑被病毒入侵之后有哪些症状和解决方法...
  9. 稳定触发windows蓝屏的路径漏洞,不要用来整人!
  10. 高等代数 具有度量的线性空间(第10章)5 正交空间与辛空间
  11. python实现工作流审批_工作流和审批流
  12. iOS - CAEmitterlayer粒子发射器
  13. 【Navicat】Navicat Premium12 下载、安装、激活、过期解决方法 —— 永久有效
  14. Codeforces 1593C Save More Mice
  15. 如何快速学linux?
  16. 「Python条件结构」将两个数从小到大输出
  17. Python入门——组合数据类型
  18. 不会吧!做了两年建模师你还不清楚3D游戏角色制作过程
  19. laydate使用详解
  20. PHP 实现大数据(30w量级)表格导出(导出excel) 提高效率,减少内存消耗,终极解决方案

热门文章

  1. Spring这棵大树
  2. YaoLingJump开发者日志(七)
  3. hook_theme 的重要性
  4. MySql DATE_FORMAT函数用法
  5. zabbix安装步骤
  6. IntelliJ IDEA 使用随笔
  7. 使用ocr的自动备份还原ocr
  8. SharedSDK微信分享不成功,分享之后没有反应
  9. numpy 函数一:linspace
  10. 为什么装了ACDSEE 就不能点网站上的连接?