Codeforces Round #537 (Div. 2)B. Average Superhero Gang Power (貪心+暴力)
題目連結:http://codeforces.com/contest/1111/problem/B
#include<bits/stdc++.h>
using namespace std;
#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long
#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<ll,ll>
#define mk(x,y) make_pair(x,y)
const int maxn=1e5+9;
const int mod=998244353;
const int ub=1e6;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*
題目大意:給定一個長度為n的序列,要求可以執行m次操作,
每次操作可以把一個人的權值加一,可以刪除一個人(如果刪除後人數不為空),
但每個人增長的權值最大值為k,問執行操作後其序列平均值是多少。
題目分析:貪心,假設刪除了x次,增長了y次,
其刪除的肯定是數值最小的,所以把原陣列排個序,然後列舉刪除的次數即可。
時間複雜度:O(n).
*/
ll a[maxn];
ll sum[maxn];
ll n,k,m;
int main()
{
cin>>n>>k>>m;
sum[0]=0LL;
for(int i=1;i<=n;i++) cin>>a[i];
sort(a+1,a+n+1);
rep(i,1,n+1) sum[i]=sum[i-1]+a[i];
double ans=1.0*sum[n]/n;
rep(i,0,n) if(i<=m){
int tm=m-i;
ans=max(ans,1.0*(sum[n]-sum[i]+1.0*min(1LL*tm,(n-i)*k))/(n-i));
}
else break;
printf("%.7f\n",ans);
return 0;
}
相關文章
- Codeforces Round #537 (Div. 2)解題報告
- Codeforces Round #537 (Div. 2)C Creative Snap (分治)
- Educational Codeforces Round 167 (Rated for Div. 2) D(dp,貪心)
- Codeforces Round #491 (Div. 2) B. Getting an A
- Educational Codeforces Round 99 (Rated for Div. 2) D. Sequence and Swaps(貪心)
- Codeforces Round #676 (Div. 2) B. Putting Bricks in the Wall
- 貪心:Codeforces Round #674 (Div. 3) E Rock, Paper, Scissors s
- Codeforces Round 928 (Div. 4) B. Vlad and Shapes
- Codeforces Round 946 (Div. 3) G Money Buys Less Happiness Now(反悔貪心)APP
- Codeforces Round #541 (Div. 2)
- Codeforces Round 940 (Div. 2)
- Codeforces Round 934 (Div. 2)
- Codeforces Round 932 (Div. 2)
- Codeforces Round 948 (Div. 2)
- Codeforces Round #639 (Div. 2)
- Codeforces Round #672 (Div. 2)
- Codeforces Round #682 (Div. 2)
- Codeforces Round #678 (Div. 2)
- Codeforces Round #673 (Div. 2)
- Codeforces Round 987 (Div. 2)
- Codeforces Round 976 (Div. 2)
- Codeforces Round 975 (Div. 2)
- Codeforces Round 986 (Div. 2)
- Codeforces Round 973 (Div. 2)
- Codeforces Round 969 (Div. 2)
- Codeforces Round 873 (Div. 2)
- Codeforces Round 967 (Div. 2)
- Codeforces Round 965 (Div. 2)
- Codeforces Round 963 (Div. 2)
- Codeforces Round 979 (Div. 2)
- Codeforces Round 972 (Div. 2)
- Codeforces Round 949 (Div. 2)
- Codeforces Round 955 (Div. 2)
- Codeforces Round 951 (Div. 2)
- Codeforces Round 961 (Div. 2)
- Codeforces Round 958 (Div. 2)
- Codeforces Round 960 (Div. 2)
- Codeforces Round 953 (Div. 2)