結果

問題 No.972 選び方のスコア
ユーザー risujirohrisujiroh
提出日時 2020-01-17 22:02:01
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 651 bytes
コンパイル時間 1,589 ms
コンパイル使用メモリ 171,932 KB
実行使用メモリ 5,516 KB
最終ジャッジ日時 2023-09-08 02:57:55
合計ジャッジ時間 4,624 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
5,324 KB
testcase_01 AC 58 ms
5,436 KB
testcase_02 AC 53 ms
5,056 KB
testcase_03 AC 28 ms
4,380 KB
testcase_04 AC 57 ms
5,372 KB
testcase_05 AC 55 ms
5,324 KB
testcase_06 AC 56 ms
5,380 KB
testcase_07 AC 42 ms
4,856 KB
testcase_08 AC 43 ms
5,376 KB
testcase_09 AC 41 ms
5,336 KB
testcase_10 AC 42 ms
5,320 KB
testcase_11 AC 42 ms
5,320 KB
testcase_12 AC 42 ms
5,388 KB
testcase_13 AC 43 ms
5,432 KB
testcase_14 AC 42 ms
5,456 KB
testcase_15 AC 45 ms
5,376 KB
testcase_16 AC 43 ms
5,332 KB
testcase_17 AC 45 ms
5,436 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 55 ms
5,476 KB
testcase_20 AC 54 ms
5,516 KB
testcase_21 AC 55 ms
5,376 KB
testcase_22 AC 53 ms
5,412 KB
testcase_23 AC 54 ms
5,376 KB
testcase_24 AC 54 ms
5,440 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto&& e : a) {
    cin >> e;
  }
  sort(begin(a), end(a));
  vector<long long> c(n + 1);
  for (int i = n; i--; ) {
    c[i] = a[i] + c[i + 1];
  }
  long long res = 0;
  for (int m = 1; m < n - 1; ++m) {
    int ok = 0, ng = min(m, n - m - 1) + 1;
    while (ng - ok > 1) {
      int mid = (ok + ng) / 2;
      (a[m - mid] + a[n - mid] > 2 * a[m] ? ok : ng) = mid;
    }
    res = max(res, (c[m - ok] - c[m]) + (c[n - ok] + c[n]) - (long long)a[m] * (2 * ok));
  }
  cout << res << '\n';
}
0