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

Posted lu1nacy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 team having powers a1,a2,,ana1,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 11. They can do at most mmoperations. Also, on a particular superhero at most kk 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 nn, kk and mm (1n1051≤n≤105, 1k1051≤k≤105, 1m1071≤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 nn integers a1,a2,,ana1,a2,…,an (1ai1061≤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?610?6.

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

 

Examples
input
2 4 6
4 7
output
11.00000000000000000000
input
4 2 6
1 3 2 3
output
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 22 each.

 

题意:找到最大平均数;可以对每个数字进行两种操作,删除或加K;最大m次操作

 

思路:暴力,但是我没做出来,看的题解思路,然后发现很多需要注意的细节,wa了很多次;

首先要求出所有数的和,应该用long long 型存;

 

注意数组如果是从0开始存储,那应该加上特例,只有一个数的情况;

为避免溢出,我的n,k,m也是long long型;

 

代码如下:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define ll long long
 4 
 5 ll an[100005];
 6 int main()
 7 {
 8     ll n,k,m;
 9     while(cin >> n >> k >> m)
10     {
11         an[0] = 0;
12         for(int i = 1;i <= n;i++)
13         cin >> an[i];
14         sort(an + 1,an + 1 + n);
15         for(int i = 1;i <= n;i++)
16         {
17             an[i] += an[i - 1];
18         }
19         double res = an[n] * 1.0 / n;
20         for(ll i = 0;i < n;i++)
21         {
22             if(i > m)
23             break;
24             ll add = min((m - i),(n - i) * k) * 1.0;
25             res = max(res,((an[n] - an[i] + add) * 1.0 / (n - i) ));
26         }
27         printf("%.10f
",res);
28     }
29     return 0;
30 }

 

 

以上是关于CodeCraft-19 and Codeforces Round #537 (Div. 2) B. Average Superhero Gang Power的主要内容,如果未能解决你的问题,请参考以下文章

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

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

CodeCraft-19 and Codeforces Round #537 (Div. 2) - D. Destroy the Colony(动态规划+组合数学)

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

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

CodeCraft-19 and Codeforces Round #537 Div. 2