結果

問題 No.972 選び方のスコア
ユーザー risujirohrisujiroh
提出日時 2020-01-17 21:37:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 717 bytes
コンパイル時間 1,607 ms
コンパイル使用メモリ 171,652 KB
実行使用メモリ 5,672 KB
最終ジャッジ日時 2023-09-08 01:53:54
合計ジャッジ時間 4,448 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
5,404 KB
testcase_01 AC 40 ms
5,344 KB
testcase_02 AC 39 ms
5,052 KB
testcase_03 AC 20 ms
4,376 KB
testcase_04 AC 41 ms
5,332 KB
testcase_05 AC 40 ms
5,348 KB
testcase_06 AC 41 ms
5,372 KB
testcase_07 AC 32 ms
4,828 KB
testcase_08 AC 28 ms
5,432 KB
testcase_09 AC 27 ms
5,344 KB
testcase_10 AC 27 ms
5,312 KB
testcase_11 AC 28 ms
5,320 KB
testcase_12 AC 29 ms
5,396 KB
testcase_13 AC 29 ms
5,360 KB
testcase_14 AC 29 ms
5,344 KB
testcase_15 AC 30 ms
5,340 KB
testcase_16 AC 30 ms
5,320 KB
testcase_17 AC 30 ms
5,352 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,384 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 2 ms
4,380 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 k = 3; k <= n; ++k) {
    long long crr = 0;
    if (~k & 1) {
      crr += c[0] - c[k / 2 + 1];
      crr += c[n - (k / 2 - 1)] - c[n];
      crr -= (long long)(a[k / 2 - 1] + a[k / 2]) * k / 2;
    } else {
      crr += c[0] - c[(k + 1) / 2];
      crr += c[n - k / 2] - c[n];
      crr -= (long long)a[k / 2] * k;
    }
    res = max(res, crr);
  }
  cout << res << '\n';
}
0