結果

問題 No.972 選び方のスコア
ユーザー finefine
提出日時 2020-01-17 22:01:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 912 bytes
コンパイル時間 1,714 ms
コンパイル使用メモリ 170,148 KB
実行使用メモリ 6,348 KB
最終ジャッジ日時 2023-09-08 02:57:50
合計ジャッジ時間 4,929 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
6,220 KB
testcase_01 AC 60 ms
6,116 KB
testcase_02 AC 57 ms
5,852 KB
testcase_03 AC 29 ms
4,584 KB
testcase_04 AC 59 ms
6,156 KB
testcase_05 AC 58 ms
6,348 KB
testcase_06 AC 59 ms
6,224 KB
testcase_07 AC 44 ms
5,436 KB
testcase_08 AC 45 ms
6,216 KB
testcase_09 AC 43 ms
5,904 KB
testcase_10 AC 44 ms
6,232 KB
testcase_11 AC 46 ms
6,344 KB
testcase_12 AC 46 ms
6,156 KB
testcase_13 AC 46 ms
6,256 KB
testcase_14 AC 46 ms
6,160 KB
testcase_15 AC 48 ms
6,152 KB
testcase_16 AC 47 ms
6,220 KB
testcase_17 AC 48 ms
6,272 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 57 ms
6,208 KB
testcase_20 AC 57 ms
6,256 KB
testcase_21 AC 56 ms
6,260 KB
testcase_22 AC 56 ms
5,964 KB
testcase_23 AC 57 ms
6,348 KB
testcase_24 AC 56 ms
6,228 KB
testcase_25 AC 1 ms
4,384 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,384 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 (a[n - mid] + a[i - mid] >= a[i] * 2) 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