結果

問題 No.972 選び方のスコア
ユーザー trineutrontrineutron
提出日時 2020-01-18 04:37:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 562 bytes
コンパイル時間 1,504 ms
コンパイル使用メモリ 170,884 KB
実行使用メモリ 4,888 KB
最終ジャッジ日時 2023-09-08 15:47:07
合計ジャッジ時間 5,217 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
4,540 KB
testcase_01 AC 89 ms
4,628 KB
testcase_02 AC 85 ms
4,636 KB
testcase_03 AC 41 ms
4,380 KB
testcase_04 AC 82 ms
4,884 KB
testcase_05 AC 81 ms
4,616 KB
testcase_06 AC 81 ms
4,716 KB
testcase_07 AC 67 ms
4,380 KB
testcase_08 AC 73 ms
4,568 KB
testcase_09 AC 71 ms
4,640 KB
testcase_10 AC 71 ms
4,700 KB
testcase_11 AC 76 ms
4,644 KB
testcase_12 AC 77 ms
4,888 KB
testcase_13 AC 77 ms
4,588 KB
testcase_14 AC 77 ms
4,748 KB
testcase_15 AC 78 ms
4,616 KB
testcase_16 AC 78 ms
4,588 KB
testcase_17 AC 78 ms
4,624 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 78 ms
4,616 KB
testcase_20 AC 77 ms
4,536 KB
testcase_21 AC 77 ms
4,676 KB
testcase_22 AC 78 ms
4,592 KB
testcase_23 AC 77 ms
4,568 KB
testcase_24 AC 77 ms
4,568 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    int n;
    cin >> n;
    vector<int64_t> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    int64_t s = 0, k = 0, del = 0, ans = 0;
    for (int64_t i = 0; i < (n - 1) / 2; i++) {
        int64_t p = a[i + 1];
        s += a[i] + a[n - 1 - k];
        k++;
        while (k > 0 && a[n - k] - p < p - a[del]) {
            s -= a[del] + a[n - k];
            del++;
            k--;
        }
        ans = max(ans, s - 2 * k * p);
    }
    cout << ans << endl;
}
0