結果

問題 No.972 選び方のスコア
ユーザー MayimgMayimg
提出日時 2020-01-20 15:13:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 742 bytes
コンパイル時間 2,086 ms
コンパイル使用メモリ 204,776 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2023-09-15 21:01:39
合計ジャッジ時間 5,092 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
6,164 KB
testcase_01 AC 59 ms
6,100 KB
testcase_02 AC 56 ms
5,888 KB
testcase_03 AC 28 ms
4,628 KB
testcase_04 AC 57 ms
6,112 KB
testcase_05 AC 58 ms
6,104 KB
testcase_06 AC 57 ms
6,160 KB
testcase_07 AC 43 ms
5,516 KB
testcase_08 AC 45 ms
6,148 KB
testcase_09 AC 43 ms
5,896 KB
testcase_10 AC 43 ms
6,200 KB
testcase_11 AC 45 ms
6,196 KB
testcase_12 AC 45 ms
6,156 KB
testcase_13 AC 45 ms
6,144 KB
testcase_14 AC 45 ms
6,204 KB
testcase_15 AC 46 ms
6,196 KB
testcase_16 AC 47 ms
6,236 KB
testcase_17 AC 46 ms
6,212 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 56 ms
6,212 KB
testcase_20 AC 56 ms
6,264 KB
testcase_21 AC 55 ms
6,208 KB
testcase_22 AC 55 ms
5,884 KB
testcase_23 AC 55 ms
6,272 KB
testcase_24 AC 55 ms
6,196 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,376 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 1 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector<long long> a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  vector<long long> sum(n + 1);
  for (int i = 1; i <= n; i++) {
    sum[i] = sum[i - 1] + a[i];
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    int lo = 0, hi = min(i - 1, n - i) + 1;
    while (hi - lo > 1) {
      int mid = (lo + hi) >> 1;
      if (a[n - mid + 1] - a[i] >= a[i] - a[i - mid]) lo = mid;
      else hi = mid;
    }
    ans = max(ans, sum[n] - sum[n - lo] + sum[i - 1] - sum[i - 1 - lo] - lo * a[i] * 2);
  }
  cout << ans << '\n';
  return 0;
}
0