結果

問題 No.972 選び方のスコア
ユーザー ytftytft
提出日時 2021-04-11 15:45:49
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 863 bytes
コンパイル時間 1,699 ms
コンパイル使用メモリ 171,844 KB
実行使用メモリ 5,692 KB
最終ジャッジ日時 2023-09-09 18:03:47
合計ジャッジ時間 7,019 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 90 ms
5,340 KB
testcase_11 AC 95 ms
5,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 1 ms
4,380 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
4,384 KB
testcase_26 AC 2 ms
4,384 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,384 KB
testcase_32 WA -
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    vector<int> a(N);
    for(int i=0;i<N;++i){
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    int rang,m,M,mid;
    int ans=0;
    vector<int> b(N);
    b[0]=a[0];
    for(int i=1;i<N;i++){
        b[i]=a[i]+b[i-1];
    }
    function<int(int,int)> s=[b,N](int s,int t){
        if(s==0){
            return b[t];
        }else if(s==N){
            return 0;
        }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