Submission #1217275

#TimeUsernameProblemLanguageResultExecution timeMemory
1217275Adeeb_obedoSeesaw (JOI22_seesaw)C++20
0 / 100
0 ms328 KiB
#include<bits/stdc++.h>
#define int long long
#define ld   double
#define _1 first
#define _2 second
#define yes cout<<"Yes\n"
#define nah cout<<"No\n"
#define FFF ios_base::sync_with_stdio(0);cin.tie(0);
#define ipr pair<int,int>
#define ret return
#define intt int32_t
#define mid ((l+r)/2)
#define pb push_back
#define lll __int128
using namespace std;
int tst, ts;
intt mo = 998244353, dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0};
int mul( int x, int y ) {
    ret ( ( x % mo ) * ( y % mo ) ) % mo;
    ret x*y;
}
int pwo( int x, int y ) {
    int res = 1;
    for( int i = 63; i + 1; i-- )
        res = mul( res, res * ( ( 1ll << i )&y ? x : 1 ) );
    ret res;
}
int dvii( int x, int y ) {
    ret mul( x, pwo( y, mo - 2 ) );
}
int oo( char x ) {
    ret ( int )x - '0';
}
int lgg( int x, int y ) {
    int u = 0;
    while( x ) {
        u++;
        x /= y;
    }
    ret u;
}
int mun( int x, int y ) {
    while( x < y )x += mo;
    ret ( x - y ) % mo;
}
int add( int x, int y ) {
    ret x + y - ( mo * ( x + y >= mo ) );
    ret x + y;
}
int lcm( int x, int y ) {
    ret ( x * y ) / __gcd( x, y );
}
#define endl '\n';
const int M =2007, N = 2e5+ 7, N2 = 5e3 + 7, inf = 2e18+7 ;
double n,a[N],s,k;
struct ooo{
double an,mx,mn;
int o;
}dp[M][M];
void sol(int l, int r,double su){
if(dp[l][r].o)
	ret;
if(l==r){
	dp[l][r].mx=max(s,a[l]),dp[l][r].mn=min(s,a[l]);
	dp[l][r].an=dp[l][r].mx-dp[l][r].mn;
	ret;
}
sol(l+1,r,su-a[l]),sol(l,r-1,su-a[r]);
ooo u,p;
su/=(r-l+1);
u.mn=min(su,dp[l+1][r].mn);
u.mx=max(su,dp[l+1][r].mx);
u.an=u.mx-u.mn;
p.mn=min(su,dp[l][r-1].mn);
p.mx=max(su,dp[l][r-1].mx);
p.an=p.mx-p.mn;
if(p.an<u.an)
	dp[l][r]=p;
else
	dp[l][r]=u;
dp[l][r].o=1;
}
void solve(){
	cin>>n;
	 double p=0;
	 s=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		s+=a[i];
	}
	p=s;s/=n;
	sol(0,n-1,p);
	cout<<fixed<<setprecision(10);
	cout<<dp[0][(int )n-1].an+0.0000000001<<endl;
}
intt main() {
	FFF
	//freopen("fcolor.in", "r", stdin);
	//freopen("fcolor.out", "w", stdout);
	tst = 1;
	//cin >> tst;
    for ( ts = 1; ts <= tst; ts++ ){
		solve();
   }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...