CF w1d2 B. Average Superhero Gang Power

Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations.

Initially, there are n superheroes in avengers team having powers a1,a2,…,an, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by 1. They can do at most m operations. Also, on a particular superhero at most k operations can be done.

Can you help the avengers team to maximize the average power of their crew?

Input

The first line contains three integers n, k and m (1≤n≤105, 1≤k≤105, 1≤m≤107) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations.

The second line contains n integers a1,a2,…,an (1≤ai≤106) — the initial powers of the superheroes in the cast of avengers.

Output

Output a single number — the maximum final average power.

Your answer is considered correct if its absolute or relative error does not exceed 10?6.

Formally, let your answer be a, and the jury‘s answer be b. Your answer is accepted if and only if |a?b|max(1,|b|)≤10?6.

Examples

inputCopy

2 4 6

4 7

outputCopy

11.00000000000000000000

inputCopy

4 2 6

1 3 2 3

outputCopy

5.00000000000000000000

Note

In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times.

In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by 2 each.

看了标程才会。。太难了。。

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a[100005],sum,n,m,k,num,tmp;
double ans;
int main()
{
	cin>>n>>k>>m;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	sort(a,a+n);
	num=n;
	ans=(double)(sum+min(n*k,m))/n;
	for(int i=1;i<n&&i<=m;i++)
	{
		sum-=a[i-1];
		tmp=sum+min(k*(n-i),m-i);
		ans=max(ans,(double)tmp/(double)(n-i));
	}
	cout<<fixed<<setprecision(20)<<ans;
	//printf("%llf",ans);
	return 0;
}

原文地址:https://www.cnblogs.com/LiangYC1021/p/12670495.html

时间: 2024-10-30 17:36:37

CF w1d2 B. Average Superhero Gang Power的相关文章

CodeCraft-19 and Codeforces Round #537 (Div. 2) B. Average Superhero Gang Power

题目描述: Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are nn superheroes in avengers tea

CF-1111B-Average Superhero Gang Power

首先,对于这题我们要知道要删除一个数使平均值最大一定是删除最小的数,然后我们假设删除操作执行了i次,也就是删除最小的i个数.在已知删除操作次数之后求增加操作的次数就容易了,当然是m - i和k * (n - i)中比较小的数啦.用一个ans变量记录结果,遍历i,更新ans,得到最终的ans. B - Average Superhero Gang Power GNU C++11 Accepted 46 ms 400 KB #include "bits/stdc++.h" using na

CF w1d2 A. Superhero Transformation

Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are n superheroes in avengers team havin

CodeCraft-19 and Codeforces Round #537 (Div. 2)

A. Superhero Transformation 水题,注意两个字符串可能长度不相等. #include<bits/stdc++.h> #define clr(a,b) memset(a,b,sizeof(a)) using namespace std; typedef long long ll; const int maxn=100010; map<char ,int >m; int main(){ m['a']=m['e']=m['i']=m['o']=m['u']=1;

codeforces contest 1111

A. Superhero Transformation 题意: 元音和元音,辅音和辅音字母之间可以互相转换,问两个字符串是否想同: 题解:直接判断即可: 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=1010; 4 char s[N]; 5 int n,m,vis1[N],vis2[N]; 6 int judge(char x){return x=='a'||x=='e'||x=='i'||x=='o'||x=='

Python与rrdtool的结合模块

rrdtool(round robin database)工具为环状数据库的存储格式,round robin是一种处理定量数据以及当前元素指针的技术.rrdtool主要用来跟踪对象的变化情况,生成这些变化的走势图,比如业务的访问流量.系统性能.磁盘利用率等趋势图,很多流行监控平台都使用到rrdtool,比较有名的为Cacti.Ganglia.Monitorix等.更多rrdtool介绍见官网http://oss.oetiker.ch/rrdtool/.rrdtool是一个复杂的工具,涉及较多参数

[TypeScript] Using Assertion to Convert Types in TypeScript

Sometimes the compiler needs help figuring out a type. In this lesson we learn how to help out the compiler with Typescript type assertion. We have a SuperHero and a BadGuy. Let's make a function that saves the day if the function's argument is a Sup

Cacti详解

实现监控的方式: SNMP 命令.脚本(remote script) Cacti(php脚本) 强大的绘图引擎 将其他监控软件收集的数据通过图形的方式展示 时间序列数据的展示工具 Nagios 状态监控工具 监控的对象: Fault Management故障管理 Configuration Management配置管理 Accounting Management统计管理 Performance Management性能管理 Security Management安全管理 SNMP--------

Cacti(php脚本)

实现监控的方式: SNMP 命令.脚本(remote script) 强大的绘图引擎 将其他监控软件收集的数据通过图形的方式展示 时间序列数据的展示工具 Nagios 状态监控工具 监控的对象: Fault Management故障管理 Configuration Management配置管理 Accounting Management统计管理 Performance Management性能管理 Security Management安全管理 SNMP----------Simple Netw