結果

問題 No.972 選び方のスコア
ユーザー Fu_L
提出日時 2021-03-16 00:10:14
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 865 bytes
コンパイル時間 5,766 ms
コンパイル使用メモリ 251,192 KB
最終ジャッジ日時 2025-01-19 17:28:03
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<ll,ll> P;
typedef modint1000000007 mint;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
const ll inf=1e18;
ll n,a[200005];
ll b[200005],c[200005];
ll ans;
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin>>n;
    rep(i,0,n) cin>>a[i];
    sort(a,a+n);
    rep(i,0,n){
        b[i+1]=b[i]+a[i];
        c[i+1]=c[i]+a[n-1-i];
    }
    if(n<=2){
        cout<<0<<endl;
        return 0;
    }
    ans=(a[0]-a[1])+(a[n-1]-a[1]);
    rep(i,4,n+1){
        ll m;
        if(i%2==0){
            m=(a[n-i/2]+a[i/2-1]);
            ans=max(ans,b[i/2]+c[i/2]-m*(i/2));
        }else{
            m=a[i/2];
            ans=max(ans,b[i/2+1]+c[i/2]-m*i);
        }
    }
    cout<<ans<<endl;

}
0