結果

問題 No.972 選び方のスコア
ユーザー minato
提出日時 2020-01-17 23:21:17
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,273 bytes
コンパイル時間 3,146 ms
コンパイル使用メモリ 181,024 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-26 00:44:21
合計ジャッジ時間 4,487 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25 WA * 7
権限があれば一括ダウンロードができます

ソースコード

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