結果

問題 No.972 選び方のスコア
ユーザー betrue12betrue12
提出日時 2020-01-17 22:31:43
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 109 ms / 2,000 ms
コード長 604 bytes
コンパイル時間 2,846 ms
コンパイル使用メモリ 203,180 KB
実行使用メモリ 6,480 KB
最終ジャッジ日時 2023-09-08 04:48:57
合計ジャッジ時間 6,250 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
6,124 KB
testcase_01 AC 109 ms
6,196 KB
testcase_02 AC 103 ms
6,032 KB
testcase_03 AC 50 ms
4,712 KB
testcase_04 AC 101 ms
6,204 KB
testcase_05 AC 102 ms
6,264 KB
testcase_06 AC 102 ms
6,432 KB
testcase_07 AC 82 ms
5,412 KB
testcase_08 AC 90 ms
6,160 KB
testcase_09 AC 87 ms
6,168 KB
testcase_10 AC 90 ms
6,432 KB
testcase_11 AC 95 ms
6,296 KB
testcase_12 AC 95 ms
6,160 KB
testcase_13 AC 95 ms
6,296 KB
testcase_14 AC 95 ms
6,332 KB
testcase_15 AC 96 ms
6,168 KB
testcase_16 AC 98 ms
6,216 KB
testcase_17 AC 98 ms
6,480 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 97 ms
6,128 KB
testcase_20 AC 97 ms
6,352 KB
testcase_21 AC 95 ms
6,296 KB
testcase_22 AC 97 ms
6,028 KB
testcase_23 AC 96 ms
6,352 KB
testcase_24 AC 96 ms
6,256 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int64_t> A(N), S(N+1);
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    for(int i=0; i<N; i++) S[i+1] = S[i] + A[i];

    int64_t ans = 0;
    for(int i=0; i<N; i++){
        int ok = 0, ng = min(i, N-1-i)+1;
        while(ng-ok>1){
            int m = (ok+ng)/2;
            (A[N-m]+A[i-m] > 2*A[i] ? ok : ng) = m;
        }
        int64_t res = S[N] - S[N-ok] + S[i] - S[i-ok] - 2*ok*A[i];
        ans = max(ans, res);
    }
    cout << ans << endl;
    return 0;
}
0