結果

問題 No.972 選び方のスコア
ユーザー kimiyukikimiyuki
提出日時 2020-01-18 02:12:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 906 bytes
コンパイル時間 2,222 ms
コンパイル使用メモリ 205,252 KB
実行使用メモリ 8,036 KB
最終ジャッジ日時 2023-09-08 12:27:41
合計ジャッジ時間 6,307 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
7,808 KB
testcase_01 AC 93 ms
7,720 KB
testcase_02 AC 88 ms
7,456 KB
testcase_03 AC 43 ms
5,652 KB
testcase_04 AC 85 ms
7,840 KB
testcase_05 AC 84 ms
7,728 KB
testcase_06 AC 85 ms
7,732 KB
testcase_07 AC 69 ms
6,392 KB
testcase_08 AC 74 ms
7,824 KB
testcase_09 AC 71 ms
7,464 KB
testcase_10 AC 75 ms
7,712 KB
testcase_11 AC 79 ms
7,860 KB
testcase_12 AC 80 ms
7,772 KB
testcase_13 AC 80 ms
8,032 KB
testcase_14 AC 81 ms
7,816 KB
testcase_15 AC 81 ms
7,864 KB
testcase_16 AC 82 ms
7,828 KB
testcase_17 AC 81 ms
7,876 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,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2 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,380 KB
testcase_34 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define ALL(x) std::begin(x), std::end(x)
using namespace std;
template <class T, class U> inline void chmax(T & a, U const & b) { a = max<T>(a, b); }
template <typename T> istream & operator >> (istream & in, vector<T> & xs) { REP (i, xs.size()) { in >> xs[i]; } return in; }

int64_t solve(int n, vector<int64_t> a) {
    sort(ALL(a));
    vector<int64_t> acc(n + 1);
    partial_sum(ALL(a), acc.begin() + 1);

    int64_t ans = INT64_MIN;
    REP (i, (n + 1) / 2) {
        chmax(ans, a[i] + (acc[i] - acc[0]) + (acc[n] - acc[n - i]) - (2 * i + 1) * a[i]);
        chmax(ans, a[i] + a[i + 1] + (acc[i] - acc[0]) + (acc[n] - acc[n - i]) - (2 * i + 2) * (a[i] + a[i + 1]) / 2);
    }
    return ans;
}

int main() {
    int n; cin >> n;
    vector<int64_t> a(n); cin >> a;
    cout << solve(n, a) << endl;
    return 0;
}
0