【CodeForces - 735B】Urbanization (找规律,思维)

题干:

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

题目大意:

       给你n个数,在这n个数中取n1个数和n2个数,求出平均值a1,a2,使他们的平均值和最大。

解题报告:

      假设n1城市的人少,n2城市的人数多,最富的人去n1,剩下的填满n2即可,注意用longlong,,好坑这一点,又忘开longlong了。

AC代码:

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAX = 1e5 + 5 ;
ll n,n1,n2,tmp;
int a[MAX];
bool cmp(ll a,ll b) {return a > b;
}
int main()
{cin>>n>>n1>>n2;for(int i = 1; i<=n; i++) {cin>>a[i];}sort(a+1,a+n+1,cmp);if(n1 > n2) swap(n1,n2);for(int i = 1; i<=n1; i++) {tmp += a[i];}double ans = tmp * 1.0 / n1;tmp = 0;for(int i = n1+1; i<=n1 + n2; i++) {tmp += a[i];}ans += tmp*1.0/n2;printf("%.6f\n",ans);return 0 ;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441725.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

java 文本查找_Java基于正则表达式实现查找匹配的文本功能【经典实例】

本文实例讲述了Java基于正则表达式实现查找匹配的文本功能。分享给大家供大家参考&#xff0c;具体如下&#xff1a;REMatch.java&#xff1a;package reMatch;import java.util.regex.Matcher;import java.util.regex.Pattern;/*** Created by Frank*/public class REMatch {p…

【51nod - 1073】约瑟夫环问题模板

题干&#xff1a; N个人坐成一个圆环&#xff08;编号为1 - N&#xff09;&#xff0c;从第1个人开始报数&#xff0c;数到K的人出列&#xff0c;后面的人重新从1开始报数。问最后剩下的人的编号。 例如&#xff1a;N 3&#xff0c;K 2。2号先出列&#xff0c;然后是1号&am…

java oracle database user dsn_跨会话序列化数据库连接

我正在开发一个web应用程序&#xff0c;它需要使用最终用户提供的凭据登录到数据库&#xff1b;应用程序本身没有登录到数据库。在问题是如何为每个用户会话创建一个连接。在一种方法是&#xff1a;请求用户凭据检查针对数据库后端的凭据是否有效在会话级变量中存储凭据这种方法…

【POJ - 3125 】Printer Queue(模拟,队列+优先队列,STL)

题干&#xff1a; The only printer in the computer science students union is experiencing an extremely heavy workload. Sometimes there are a hundred jobs in the printer queue and you may have to wait for hours to get a single page of output. Because some …

java循环单链表类构造函数_C++实现双向循环链表

本文实例为大家分享了C实现双向循环链表的具体代码&#xff0c;供大家参考&#xff0c;具体内容如下一、概念1.在双链表中的每个结点应有两个链接指针&#xff1a;lLink -> 指向前驱结点 (前驱指针或者左链指针)rLink->指向后继结点(后驱指针或者右链指针)2.双链表常采用…

*【CodeForces - 799C】Fountains (线段树 或 树状数组,类似二元组问题)

题干&#xff1a; Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cos…

java 前后的区别_java中前后++的区别

java中前后的区别发布时间&#xff1a;2020-06-22 14:38:22来源&#xff1a;亿速云阅读&#xff1a;134作者&#xff1a;Leah这篇文章将为大家详细讲解有关java中前后的区别&#xff0c;小编觉得挺实用的&#xff0c;因此分享给大家做个参考&#xff0c;希望大家阅读完这篇文章…

【CodeForces - 735A 】Ostap and Grasshopper (水题,模拟)

题干&#xff1a; On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grassh…

java私有成员的访问_java – 使用私有成员或公共访问器的方法

我意识到这可能无法回答,但我正在寻找是否有关于是否直接使用私有成员或类方法中的公共访问器的某种指导.例如,考虑以下代码(在Java中,但在C中看起来非常相似)&#xff1a;public class Matrix {// Private Membersprivate int[][] e;private int numRows;private int numCols;…

☆【CodeForces - 764C】Timofey and a tree (思维题,树的性质)

题干&#xff1a; Each New Year Timofey and his friends cut down a tree of n vertices and bring it home. After that they paint all the n its vertices, so that the i-th vertex gets color ci. Now its time for Timofey birthday, and his mother asked him to re…

java中实现线程互斥的关键词_简单的互斥同步方式——synchronized关键字详解

2. synchronized的原理和实现细节2.1 synchronized可以用在那些地方静态方法,锁对象为当前类的class对象,不用显式指定实例方法,锁对象为当前实例对象,不用显式指定同步代码块,锁对象为括号中指定的对象&#xff0c;必须显式指定被synchronized修饰的方法或者代码块,同一时刻只…

【51nod - 1875】 丢手绢(约瑟夫问题,可打表,用STL模拟)

题干&#xff1a; 六一儿童节到了&#xff0c;小朋友们在玩丢手绢的游戏。总共有C个小朋友&#xff0c;编号从1到C&#xff0c;他们站成一个圈&#xff0c;第i(1<i<C)个人的左边是i-1&#xff0c;第1个人的左边是C。第i(1<i<C)个人的右边是i1&#xff0c;第C个人的…

mysql server远程连接_本地远程连接 MySQL server

问题MySql Server 出于安全方面考虑默认只允许本机(localhost, 127.0.0.1)来连接访问。如果想远程访问&#xff0c;需要额外做下操作。配置修改定位文件/etc/mysql/mysql.conf.d/mysqld.cnf定位属性skip-networking #注释掉 因为它是屏蔽掉一切TCP/IP连接bind-address 127.0.0…

关闭VS警告#pragma warning(disable:4996)

代码实现&#xff1a; #pragma warning(disable:4996) 1. #pragma warning只对当前文件有效&#xff08;对于.h&#xff0c;对包含它的cpp也是有效的&#xff09;&#xff0c;而不是对整个工程的所有文件有效。当该文件编译结束&#xff0c;设置也就失去作用。 2. #pragma wa…

【CodeForces - 608C】Chain Reaction (二分 或 dp ,思维)

题干&#xff1a; 题目大意&#xff1a; 题意是在一条直线上坐落着不同位置的灯塔&#xff0c;每一个灯塔有自己的power level&#xff0c;当作是射程范围。现在从最右边的灯塔开始激发&#xff0c;如果左边的灯塔在这个灯塔的范围之内&#xff0c;那么将会被毁灭。否则会被激…

java关闭文本_如何更优雅的关闭java文本、网络等资源

通常在 java 中对文本、网络资源等操作起来是很繁杂的&#xff0c;要声明&#xff0c;读取&#xff0c;关闭三个阶段&#xff0c;还得考虑异常情况。假设我们要读取一段文本显示到控制台&#xff0c;通常会有如下的代码&#xff1a;public static void main(String[] args) {Fi…

java类匿名类实例_Java匿名类,匿名内部类实例分析

本文实例讲述了Java匿名类&#xff0c;匿名内部类。分享给大家供大家参考&#xff0c;具体如下&#xff1a;本文内容&#xff1a;内部类匿名类首发日期 &#xff1a;2018-03-25内部类&#xff1a;在一个类中定义另一个类&#xff0c;这样定义的类称为内部类。【包含内部类的类可…

【HDU - 6441】Find Integer (费马大定理 + 奇偶数列法构造勾股定理)

题干&#xff1a; people in USSS love math very much, and there is a famous math problem . give you two integers nn,aa,you are required to find 22 integers bb,cc such that ananbncnbncn. Input one line contains one integer TT;(1≤T≤1000000)(1≤T≤100000…

dart与java互调_Dart与Java不同的地方

数据类型基类是num数值型的操作运算符&#xff1a; 、 - 、* 、/ 、 ~/ 、 %/ 除法 整数余数~/ 除法 取整% 取余常用属性&#xff1a; isNaN、isEven、isOdd (是否非数字、奇偶)常用方法&#xff1a;abs()、round()、floorl()、ceil()、toInt()、toDouble()double nan 0.0 / 0…

算法学习 母函数

母函数又称生成函数。定义是给出序列:a0,a1,a2,.......ak,......,那么函数G(x)a0a1*xa2*x2......ak*xk称为序列a0,a1,a2,.......ak,......的母函数(即生成函数)。 例如&#xff1a;序列1,2,3.......n的生成函数为&#xff1a;G(x)x2x23x3........nxn。点此链接:百度百科 特别…