結果

問題 No.972 選び方のスコア
ユーザー amaridekinaiamaridekinai
提出日時 2020-01-17 22:30:24
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 668 bytes
コンパイル時間 1,566 ms
コンパイル使用メモリ 170,200 KB
実行使用メモリ 6,432 KB
最終ジャッジ日時 2023-09-08 04:44:54
合計ジャッジ時間 5,226 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
6,172 KB
testcase_01 AC 93 ms
6,300 KB
testcase_02 AC 88 ms
5,976 KB
testcase_03 AC 43 ms
4,724 KB
testcase_04 AC 85 ms
6,432 KB
testcase_05 AC 85 ms
6,164 KB
testcase_06 AC 85 ms
6,168 KB
testcase_07 AC 71 ms
5,508 KB
testcase_08 AC 76 ms
6,232 KB
testcase_09 AC 74 ms
5,852 KB
testcase_10 AC 76 ms
6,120 KB
testcase_11 AC 81 ms
6,236 KB
testcase_12 AC 81 ms
6,308 KB
testcase_13 AC 81 ms
6,116 KB
testcase_14 AC 81 ms
6,112 KB
testcase_15 AC 82 ms
6,232 KB
testcase_16 AC 82 ms
6,216 KB
testcase_17 AC 83 ms
6,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 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(){ 
  
  int n; cin >> n;
  
  vector<ll>a(n);
  
  for(int i = 0; i < n; i++){ cin >> a[i];}
  
  sort(a.begin(),a.end());
  
  vector<ll> sum(n);
  
  sum[0] = a[0];
  
  for(int i = 1; i < n; i++){
    sum[i] = sum[i-1]+a[i];
  }
  
  ll ans = 0;
  
  
  for(int i = 1; n-i > i;  i++){ //どこを中央値とするか
    
    ans = max(ans, sum[i-1]+sum[n-1]-sum[n-1-i]-2*i*a[i]);
    
  }
    
  
  
  for(int i = 2; n-i+1 > i; i++){
    
    ll m = a[i]+a[i-1];
    
    ans = max(ans, sum[i-2]+sum[n-1]-sum[n-i]-(i-1)*m);
    
  }
  
  cout << ans << endl;
  
  return 0;
}
    
  
0