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 10610−6.

Formally, let your answer be aa, and the jury's answer be bb. Your answer is accepted if and only if |ab|max(1,|b|)106|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\n",res);
28     }
29     return 0;
30 }

 

 

posted @ 2019-02-06 00:49  lu_nacy  阅读(267)  评论(0编辑  收藏  举报