結果

問題 No.972 選び方のスコア
ユーザー 👑 CleyL
提出日時 2020-01-17 21:51:26
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 464 bytes
コンパイル時間 869 ms
コンパイル使用メモリ 74,324 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-25 19:34:55
合計ジャッジ時間 4,463 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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];
    ce = a[i];
    ans = max(ans,nw-(i*2+1)*ce);
  }
  cout << ans << endl;
}
0