結果

問題 No.972 選び方のスコア
ユーザー parukiparuki
提出日時 2020-01-24 20:13:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,617 bytes
コンパイル時間 1,690 ms
コンパイル使用メモリ 171,724 KB
実行使用メモリ 6,408 KB
最終ジャッジ日時 2023-10-12 04:17:07
合計ジャッジ時間 5,024 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
6,312 KB
testcase_01 AC 71 ms
6,276 KB
testcase_02 AC 67 ms
6,000 KB
testcase_03 AC 34 ms
4,584 KB
testcase_04 AC 70 ms
6,152 KB
testcase_05 AC 69 ms
6,276 KB
testcase_06 AC 69 ms
6,292 KB
testcase_07 AC 52 ms
5,368 KB
testcase_08 AC 58 ms
6,408 KB
testcase_09 AC 56 ms
5,888 KB
testcase_10 AC 55 ms
6,156 KB
testcase_11 AC 56 ms
6,164 KB
testcase_12 AC 56 ms
6,292 KB
testcase_13 AC 57 ms
6,148 KB
testcase_14 AC 56 ms
6,276 KB
testcase_15 AC 58 ms
6,216 KB
testcase_16 AC 58 ms
6,232 KB
testcase_17 AC 58 ms
6,220 KB
testcase_18 WA -
testcase_19 AC 68 ms
6,404 KB
testcase_20 AC 67 ms
6,276 KB
testcase_21 AC 67 ms
6,288 KB
testcase_22 WA -
testcase_23 AC 67 ms
6,156 KB
testcase_24 AC 67 ms
6,160 KB
testcase_25 AC 2 ms
4,352 KB
testcase_26 AC 1 ms
4,476 KB
testcase_27 AC 2 ms
4,352 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 1 ms
4,352 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 1 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 2 ms
4,352 KB
testcase_34 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

void solve() {
    int N;
    cin >> N;
    vll A(N);
    rep(i, N) {
        cin >> A[i];
    }
    sort(all(A));
    vll sum(N + 1);
    rep(i, N) {
        sum[i + 1] = sum[i] + A[i];
    }
    ll ans = 0;
    rep(i, N) {
        ll median = A[i];
        int ok = 0, ng = min(N - i, i + 1);
        while (ng - ok > 1) {
            int x = (ok + ng) / 2;
            if (A[i - x] + A[N - i] - 2 * median > 0)ok = x;
            else ng = x;
        }
        smax(ans, (sum[i] - sum[i - ok]) + (sum[N]-sum[N-ok]) - 2ll*median*ok);
    }

    rep(i, N - 1) {
        ll median2 = A[i] + A[i + 1];
        int ok = 0, ng = min(N - (i + 1), i + 1);
        while (ng - ok > 1) {
            int x = (ok + ng) / 2;
            if (A[i - x] + A[N - i] - median2 > 0)ok = x;
            else ng = x;
        }
        smax(ans, (sum[i] - sum[i - ok]) + (sum[N] - sum[N - ok]) - median2 * ok);
    }

    cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}
0