結果

問題 No.972 選び方のスコア
ユーザー minatominato
提出日時 2020-01-17 23:21:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,273 bytes
コンパイル時間 2,854 ms
コンパイル使用メモリ 178,708 KB
実行使用メモリ 4,892 KB
最終ジャッジ日時 2023-09-08 07:28:24
合計ジャッジ時間 5,059 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
4,652 KB
testcase_01 AC 43 ms
4,628 KB
testcase_02 AC 40 ms
4,772 KB
testcase_03 AC 21 ms
4,384 KB
testcase_04 AC 42 ms
4,568 KB
testcase_05 AC 41 ms
4,640 KB
testcase_06 AC 42 ms
4,644 KB
testcase_07 AC 32 ms
4,384 KB
testcase_08 AC 27 ms
4,700 KB
testcase_09 AC 27 ms
4,688 KB
testcase_10 AC 28 ms
4,624 KB
testcase_11 AC 30 ms
4,708 KB
testcase_12 AC 29 ms
4,640 KB
testcase_13 AC 30 ms
4,588 KB
testcase_14 AC 30 ms
4,640 KB
testcase_15 AC 31 ms
4,708 KB
testcase_16 AC 31 ms
4,640 KB
testcase_17 AC 31 ms
4,572 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,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,384 KB
testcase_29 AC 1 ms
4,384 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,388 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,384 KB
testcase_34 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    sort(all(A));
    ll K = accumulate(all(A),0LL);
    ll ans = 0;
    for (ll i = N; i >= 3; i--) {
        if (i%2==0) {
            K -= (A[N-i/2]*i/2LL + A[i/2-1]*i/2LL);
            chmax(ans,K);
            K += A[N-i/2]*i/2LL + A[i/2-1]*i/2LL;
            K -= A[N-i/2];
        } else {
            K -= A[(i-1)/2]*i;
            chmax(ans,K);
            K += A[(i-1)/2]*i;
            K -= A[(i-1)/2];
        }
    }

    cout << ans << endl;
}
0