結果

問題 No.972 選び方のスコア
ユーザー 0w10w1
提出日時 2020-01-22 18:05:32
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 646 bytes
コンパイル時間 1,986 ms
コンパイル使用メモリ 204,572 KB
実行使用メモリ 5,544 KB
最終ジャッジ日時 2023-09-22 19:38:25
合計ジャッジ時間 5,080 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
5,356 KB
testcase_01 AC 58 ms
5,388 KB
testcase_02 AC 55 ms
5,520 KB
testcase_03 AC 28 ms
4,380 KB
testcase_04 AC 58 ms
5,380 KB
testcase_05 AC 57 ms
5,388 KB
testcase_06 AC 57 ms
5,360 KB
testcase_07 AC 43 ms
4,900 KB
testcase_08 AC 43 ms
5,388 KB
testcase_09 AC 41 ms
5,364 KB
testcase_10 AC 42 ms
5,424 KB
testcase_11 AC 44 ms
5,356 KB
testcase_12 AC 43 ms
5,484 KB
testcase_13 AC 43 ms
5,468 KB
testcase_14 AC 43 ms
5,484 KB
testcase_15 AC 47 ms
5,340 KB
testcase_16 AC 45 ms
5,364 KB
testcase_17 AC 46 ms
5,468 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 55 ms
5,512 KB
testcase_20 AC 54 ms
5,540 KB
testcase_21 AC 55 ms
5,380 KB
testcase_22 AC 55 ms
5,512 KB
testcase_23 AC 55 ms
5,356 KB
testcase_24 AC 55 ms
5,544 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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] - (int64_t) 2 * lb * A[i]);
  }

  cout << ans << endl;

  return 0;
}
0