結果

問題 No.972 選び方のスコア
ユーザー Fu_LFu_L
提出日時 2021-03-16 00:10:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 865 bytes
コンパイル時間 4,061 ms
コンパイル使用メモリ 254,968 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2024-04-25 03:09:44
合計ジャッジ時間 6,981 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
8,320 KB
testcase_01 AC 41 ms
8,320 KB
testcase_02 AC 41 ms
7,936 KB
testcase_03 AC 21 ms
6,016 KB
testcase_04 AC 41 ms
8,320 KB
testcase_05 AC 42 ms
8,320 KB
testcase_06 AC 41 ms
8,192 KB
testcase_07 AC 30 ms
7,168 KB
testcase_08 AC 28 ms
8,320 KB
testcase_09 AC 27 ms
7,936 KB
testcase_10 AC 28 ms
8,192 KB
testcase_11 AC 31 ms
8,320 KB
testcase_12 AC 30 ms
8,192 KB
testcase_13 AC 30 ms
8,192 KB
testcase_14 AC 30 ms
8,192 KB
testcase_15 AC 30 ms
8,192 KB
testcase_16 AC 32 ms
8,320 KB
testcase_17 AC 31 ms
8,192 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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