#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define all(x) x.begin(),x.end()
#define sz(x) int(x.size())
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
const int N = 2e5;
const int B = 2e3;
const int M = N/2;
double Tt[N], Ft[N];
double* T = &Tt[0], *F = &Ft[0];
int main(){
cin.tie(NULL),cin.sync_with_stdio(false);
int n,t; cin >> n >> t;
vd a(n);
for(auto& c : a) cin >> c;
sort(all(a),greater());
double avg = 0;
T[M] = 1;
auto calc = [&]() -> double {
double ret = 0;
int lb = max({
int(avg)+M - B,
t+M
});
int ub = int(avg)+M+B;
rep(i,lb,ub) ret += T[i];
return ret;
};
auto perform = [&](double p) -> void {
int lb = int(avg)+M-B;
int ub = int(avg)+M+B;
swap(F,T);
rep(i,lb+3,ub-3){
T[i+1] += p*F[i];
T[i-1] += (1-p)*F[i];
}
rep(i,lb,ub){
F[i] = 0;
}
avg += 2*p-1;
};
double ans = calc();
rep(i,0,n){
perform(a[i]);
ans = max(ans,calc());
}
cout << fixed << setprecision(10) << ans << '\n';
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | #include "bits/stdc++.h" using namespace std; #define rep(i,a,b) for(int i=(a); i<(b); ++i) #define all(x) x.begin(),x.end() #define sz(x) int(x.size()) typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; const int N = 2e5; const int B = 2e3; const int M = N/2; double Tt[N], Ft[N]; double* T = &Tt[0], *F = &Ft[0]; int main(){ cin.tie(NULL),cin.sync_with_stdio(false); int n,t; cin >> n >> t; vd a(n); for(auto& c : a) cin >> c; sort(all(a),greater()); double avg = 0; T[M] = 1; auto calc = [&]() -> double { double ret = 0; int lb = max({ int(avg)+M - B, t+M }); int ub = int(avg)+M+B; rep(i,lb,ub) ret += T[i]; return ret; }; auto perform = [&](double p) -> void { int lb = int(avg)+M-B; int ub = int(avg)+M+B; swap(F,T); rep(i,lb+3,ub-3){ T[i+1] += p*F[i]; T[i-1] += (1-p)*F[i]; } rep(i,lb,ub){ F[i] = 0; } avg += 2*p-1; }; double ans = calc(); rep(i,0,n){ perform(a[i]); ans = max(ans,calc()); } cout << fixed << setprecision(10) << ans << '\n'; } |
English