結果

問題 No.972 選び方のスコア
ユーザー TAISA_TAISA_
提出日時 2020-01-17 23:15:27
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,084 bytes
コンパイル時間 2,713 ms
コンパイル使用メモリ 169,284 KB
実行使用メモリ 6,380 KB
最終ジャッジ日時 2023-09-08 07:05:16
合計ジャッジ時間 4,433 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
6,160 KB
testcase_01 AC 44 ms
6,212 KB
testcase_02 AC 42 ms
5,844 KB
testcase_03 AC 22 ms
4,796 KB
testcase_04 AC 43 ms
6,164 KB
testcase_05 AC 43 ms
6,212 KB
testcase_06 AC 43 ms
6,200 KB
testcase_07 AC 33 ms
5,416 KB
testcase_08 AC 29 ms
6,088 KB
testcase_09 AC 27 ms
5,844 KB
testcase_10 AC 30 ms
6,120 KB
testcase_11 AC 31 ms
6,200 KB
testcase_12 AC 31 ms
6,204 KB
testcase_13 AC 31 ms
6,204 KB
testcase_14 AC 31 ms
6,300 KB
testcase_15 AC 32 ms
6,204 KB
testcase_16 AC 32 ms
6,208 KB
testcase_17 AC 32 ms
6,172 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 2 ms
4,384 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vll2 = vector<vector<ll>>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vll a(n + 1), sum(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    sort(a.begin() + 1, a.end());
    for (int i = 1; i <= n; i++) {
        sum[i] = sum[i - 1] + a[i];
    }
    ll res = 0;
    for (int i = 1; i <= n; i++) {
        ll s;
        if (i % 2) {
            s = sum[n] - sum[n - i / 2] + sum[i / 2] - (i - 1LL) * a[i / 2 + 1];
        } else {
            s = sum[n] - sum[n - i / 2 + 1] + sum[i / 2 - 1] -
                (i - 2LL) * (a[i / 2] + a[i / 2 + 1]) / 2LL;
        }
        chmax(res, s);
    }
    cout << res << endl;
}
0