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)解題報告
- Educational Codeforces Round 167 (Rated for Div. 2) D(dp,貪心)
- Codeforces Round #537 (Div. 2)C Creative Snap (分治)
- Codeforces Round #180 (Div. 2) D. Fish Weight 貪心
- Codeforces Round #491 (Div. 2) B. Getting an A
- Codeforces Round #242 (Div. 2) B. Megacity
- Codeforces Round #249 (Div. 2) B. Pasha Maximizes
- Codeforces Round #252 (Div. 2) B. Valera and FruitsUI
- Codeforces Round #246 (Div. 2) B. Football Kit
- Codeforces Round #244 (Div. 2) B. Prison Transfer
- Codeforces Round #336 (Div. 2) B 暴力
- Educational Codeforces Round 99 (Rated for Div. 2) D. Sequence and Swaps(貪心)
- Codeforces Round #228 (Div. 2) B. Fox and CrossROS
- Codeforces Round #215 (Div. 2) B. Sereja and Suffixes
- Codeforces Round #243 (Div. 2) B. Sereja and Mirroring
- Codeforces Round #196 (Div. 2) B. Routine Problem
- Codeforces Round #251 (Div. 2) B. Devu, the Dumb Guydev
- Codeforces Round #209 (Div. 2) B. Permutation
- 貪心:Codeforces Round #674 (Div. 3) E Rock, Paper, Scissors s
- Codeforces Round #676 (Div. 2) B. Putting Bricks in the Wall
- Codeforces Round #213 (Div. 2) B. The Fibonacci Segment
- Codeforces Round #248 (Div. 2) B. Kuriyama Mirai's StonesAI
- Codeforces Round #216 (Div. 2) B. Valera and Contest
- Codeforces Round #235 (Div. 2) B. Sereja and Contests
- Codeforces Round #233 (Div. 2) B. Red and Blue Balls
- Codeforces Round #192 (Div. 2) B. Road ConstructionStruct
- Codeforces Round #407 (Div. 1) B. Weird journey
- Codeforces Round 946 (Div. 3) G Money Buys Less Happiness Now(反悔貪心)APP
- Codeforces Round #390 (Div. 2)(A,B,C(記憶化搜尋),D(貪心,優先佇列))佇列
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) B 暴力
- Codeforces Round 928 (Div. 4) B. Vlad and Shapes
- Codeforces Round #639 (Div. 2)
- Codeforces Round #541 (Div. 2)
- Codeforces Round #682 (Div. 2)
- Codeforces Round #678 (Div. 2)
- Codeforces Round #747 (Div. 2)
- Codeforces Round #673 (Div. 2)
- Codeforces Round #672 (Div. 2)