結果

問題 No.972 選び方のスコア
ユーザー Fu_LFu_L
提出日時 2021-03-16 00:20:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 790 bytes
コンパイル時間 3,861 ms
コンパイル使用メモリ 254,944 KB
実行使用メモリ 6,784 KB
最終ジャッジ日時 2024-04-25 03:15:46
合計ジャッジ時間 6,468 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
6,784 KB
testcase_01 AC 57 ms
6,784 KB
testcase_02 AC 57 ms
6,656 KB
testcase_03 AC 28 ms
5,376 KB
testcase_04 AC 57 ms
6,656 KB
testcase_05 AC 55 ms
6,784 KB
testcase_06 AC 55 ms
6,656 KB
testcase_07 AC 41 ms
5,888 KB
testcase_08 AC 42 ms
6,784 KB
testcase_09 AC 40 ms
6,528 KB
testcase_10 AC 42 ms
6,656 KB
testcase_11 AC 43 ms
6,784 KB
testcase_12 AC 42 ms
6,784 KB
testcase_13 AC 44 ms
6,784 KB
testcase_14 AC 44 ms
6,656 KB
testcase_15 AC 43 ms
6,656 KB
testcase_16 AC 44 ms
6,656 KB
testcase_17 AC 44 ms
6,656 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 53 ms
6,784 KB
testcase_20 AC 51 ms
6,784 KB
testcase_21 AC 53 ms
6,784 KB
testcase_22 AC 53 ms
6,528 KB
testcase_23 AC 52 ms
6,784 KB
testcase_24 AC 51 ms
6,784 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 1 ms
5,376 KB
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 1 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];
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