結果

問題 No.972 選び方のスコア
ユーザー finefine
提出日時 2020-01-17 22:00:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 923 bytes
コンパイル時間 1,996 ms
コンパイル使用メモリ 170,496 KB
実行使用メモリ 6,404 KB
最終ジャッジ日時 2023-09-08 02:52:59
合計ジャッジ時間 4,951 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
6,236 KB
testcase_01 AC 62 ms
6,156 KB
testcase_02 AC 58 ms
5,816 KB
testcase_03 AC 30 ms
4,652 KB
testcase_04 AC 60 ms
6,264 KB
testcase_05 AC 60 ms
6,236 KB
testcase_06 AC 60 ms
6,404 KB
testcase_07 AC 45 ms
5,520 KB
testcase_08 AC 48 ms
6,108 KB
testcase_09 AC 46 ms
5,848 KB
testcase_10 AC 46 ms
6,400 KB
testcase_11 AC 48 ms
6,172 KB
testcase_12 AC 48 ms
6,104 KB
testcase_13 AC 48 ms
6,240 KB
testcase_14 AC 48 ms
6,292 KB
testcase_15 AC 49 ms
6,172 KB
testcase_16 AC 49 ms
6,216 KB
testcase_17 AC 50 ms
6,168 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,376 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 1 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    vector<ll> sum(n + 1, 0);
    for (int i = 0; i < n; ++i) {
        sum[i + 1] = sum[i] + a[i];
    }

    ll ans = 0, sumR = 0, sumL = 0;
    for (int i = 0; i < n; ++i) {
        int ok = 0, ng = min(i, n - 1 - i) + 1;
        while (ng - ok > 1) {
            int mid = (ok + ng) / 2;
            if (sum[n] - sum[n - mid] >= sum[i] - sum[i - mid]) ok = mid;
            else ng = mid;
        }
        //cerr << i << " " << ok << " " << sum[n] - sum[n - ok] + sum[i] - sum[i - ok] - a[i] * ok * 2 << endl;
        ans = max(ans, sum[n] - sum[n - ok] + sum[i] - sum[i - ok] - a[i] * ok * 2);
    }
    cout << ans << "\n";
    return 0;
}
0