結果

問題 No.972 選び方のスコア
ユーザー 0w10w1
提出日時 2020-01-22 18:00:26
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 636 bytes
コンパイル時間 2,028 ms
コンパイル使用メモリ 204,896 KB
実行使用メモリ 5,756 KB
最終ジャッジ日時 2023-09-22 19:18:53
合計ジャッジ時間 5,021 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 1 ms
4,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
4,376 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 2 ms
4,376 KB
testcase_30 WA -
testcase_31 AC 2 ms
4,376 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

  vector<int> A(N);
  for (int i = 0; i < N; ++i) cin >> A[i];

  sort(A.begin(), A.end());

  vector<int64_t> pa(N + 1);
  for (int i = 0; i < N; ++i) pa[i + 1] = pa[i] + A[i];

  int64_t ans = 0;
  for (int i = 0; i < N; ++i) {
    int lb = 0;
    int ub = min(i, N - (i + 1)) + 1;
    while (ub - lb > 1) {
      int mb = lb + ub >> 1;
      (A[N - mb] + A[i - mb] < 2 * A[i] ? ub : lb) = mb;
    }
    ans = max(ans, pa[N] - pa[N - lb] + pa[i] - pa[i - lb] - 2 * lb * A[i]);
  }

  cout << ans << endl;

  return 0;
}
0