結果

問題 No.972 選び方のスコア
ユーザー 👑 CleyL
提出日時 2020-01-17 22:14:31
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 575 bytes
コンパイル時間 712 ms
コンパイル使用メモリ 75,372 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-25 20:49:28
合計ジャッジ時間 4,354 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n;cin>>n;
  if(n < 3){
    cout << 0 << endl;
    return 0;
  }
  vector<long long> a(n);
  for(int i = 0; n > i; i++){
    cin>>a[i];
  }
  long long ans = 0;
  sort(a.begin(),a.end());
  long long nw = a[0];
  long long ce = a[0];
  for(int i = 1; i <= n-i; i++){
    nw += a[i]+a[n-i];
    if(i == n-1){
      nw -= a[i];
      ce = a[i-1]+a[i];
      ans = max(ans,nw-ce*n/2);
      break;
    }
    ce = a[i];
    ans = max(ans,nw-(i*2+1)*ce);
  }
  cout << ans << endl;
}
0