zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    Build-in Function:abs(),all(),any(),assii(),bin(),issubclass(),bytearray(),isinstance()
    函数及while实例
    提示'HTTP消息不可读'
    python中关于不执行if __name__ == '__main__':测试模块的解决
    python输出测试报告测试成功
    SqlServer——批量插入数据
    网页样式——各种炫酷效果持续更新ing...
    网站部署发布到互联网等整套流程
    如何远程操控别人的电脑?我来教你
    代码生成工具——CodeSmith
  • 原文地址:https://www.cnblogs.com/LiangYC1021/p/12670495.html
Copyright © 2011-2022 走看看