結果

問題 No.972 選び方のスコア
ユーザー ytftytft
提出日時 2021-04-11 15:48:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 889 bytes
コンパイル時間 1,577 ms
コンパイル使用メモリ 173,464 KB
実行使用メモリ 8,080 KB
最終ジャッジ日時 2023-09-09 18:05:23
合計ジャッジ時間 5,760 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
7,792 KB
testcase_01 AC 114 ms
7,740 KB
testcase_02 AC 107 ms
7,528 KB
testcase_03 AC 52 ms
5,364 KB
testcase_04 AC 104 ms
7,792 KB
testcase_05 AC 104 ms
7,788 KB
testcase_06 AC 104 ms
7,792 KB
testcase_07 AC 84 ms
6,544 KB
testcase_08 AC 96 ms
7,836 KB
testcase_09 AC 92 ms
7,588 KB
testcase_10 AC 93 ms
7,752 KB
testcase_11 AC 98 ms
8,080 KB
testcase_12 AC 98 ms
7,740 KB
testcase_13 AC 99 ms
7,740 KB
testcase_14 AC 98 ms
7,800 KB
testcase_15 AC 99 ms
7,748 KB
testcase_16 AC 102 ms
7,788 KB
testcase_17 AC 100 ms
7,836 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 99 ms
7,740 KB
testcase_20 AC 99 ms
7,788 KB
testcase_21 AC 99 ms
8,052 KB
testcase_22 AC 100 ms
7,484 KB
testcase_23 AC 98 ms
7,740 KB
testcase_24 AC 99 ms
7,856 KB
testcase_25 AC 1 ms
4,384 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,384 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,388 KB
testcase_30 AC 1 ms
4,388 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,384 KB
testcase_33 AC 1 ms
4,384 KB
testcase_34 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    vector<long long> a(N);
    for(int i=0;i<N;++i){
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    int rang,m,M,mid;
    long long ans=0;
    vector<long long> b(N);
    b[0]=a[0];
    for(int i=1;i<N;i++){
        b[i]=a[i]+b[i-1];
    }
    function<long long(int,int)> s=[b,N](int s,int t){
        if(s==0){
            return b[t];
        }else if(s==N){
            return 0ll;
        }else{
            return b[t]-b[s-1];
        }
    };
    for(int i=0;i<N;++i){
        rang=min(i,N-i-1);
        m=0;
        M=rang+1;
        while(M-m>1){
            mid=(M+m)/2;
            if(a[N-mid]+a[i-mid]>2*a[i]){
                m=mid;
            }else{
                M=mid;
            }
        }
        ans=max(ans,s(i-m,i)+s(N-m,N-1)-(2*m+1)*a[i]);
    }
    cout<<ans<<endl;

}
0