結果

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

ソースコード

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];
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];
    }
    rep(i,1,n-1){
        ll l=0;
        rrep(j,20,0){
            if(i-(l+(1<<j))<0) continue;
            if(n-(l+(1<<j))<i) continue;
            if(a[i-(l+(1<<j))]+a[n-(l+(1<<j))]>2*a[i]) l+=(1<<j);
        }
        ll ret=b[n]-b[n-l]+b[i]-b[i-l]-a[i]*2*l;
        ans=max(ans,ret);
    }
    cout<<ans<<endl;

}
0