結果

問題 No.972 選び方のスコア
ユーザー pekempeypekempey
提出日時 2020-01-18 08:00:41
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 839 bytes
コンパイル時間 1,511 ms
コンパイル使用メモリ 171,712 KB
実行使用メモリ 6,416 KB
最終ジャッジ日時 2023-09-09 05:37:44
合計ジャッジ時間 4,857 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
6,268 KB
testcase_01 AC 70 ms
6,212 KB
testcase_02 AC 66 ms
5,952 KB
testcase_03 AC 34 ms
4,584 KB
testcase_04 AC 68 ms
6,176 KB
testcase_05 AC 68 ms
6,164 KB
testcase_06 AC 69 ms
6,172 KB
testcase_07 AC 52 ms
5,372 KB
testcase_08 AC 56 ms
6,352 KB
testcase_09 AC 54 ms
5,996 KB
testcase_10 AC 56 ms
6,212 KB
testcase_11 AC 56 ms
6,260 KB
testcase_12 AC 56 ms
6,160 KB
testcase_13 AC 57 ms
6,168 KB
testcase_14 AC 56 ms
6,168 KB
testcase_15 AC 58 ms
6,292 KB
testcase_16 AC 58 ms
6,232 KB
testcase_17 AC 58 ms
6,220 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 67 ms
6,256 KB
testcase_20 AC 67 ms
6,328 KB
testcase_21 AC 66 ms
6,152 KB
testcase_22 AC 66 ms
6,416 KB
testcase_23 AC 67 ms
6,348 KB
testcase_24 AC 66 ms
6,136 KB
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,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int N; cin >> N;
  vector<ll> A(N); rep(i, N) cin >> A[i];
  sort(range(A));
  vector<ll> S(N + 1); rep(i, N) S[i + 1] = S[i] + A[i];
  ll ans = LLONG_MIN;
  for (int i = 0; i < N; i++) {
    int k = min(i, N - (i + 1));
    auto f = [&](int x) -> ll {
      return (S[i] - S[i - x]) + (S[N] - S[N - x]) + A[i] - A[i] * (2 * x + 1);
    };
    int l = -1;
    int r = k;
    while (r - l > 1) {
      int m = (l + r) / 2;
      if (f(m) <= f(m + 1)) l = m; else r = m;
    }
    ans = max(ans, f(r));
  }
  cout << ans << endl;
}
0