結果

問題 No.972 選び方のスコア
ユーザー monnu
提出日時 2021-04-18 00:53:57
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 633 bytes
コンパイル時間 1,593 ms
コンパイル使用メモリ 172,172 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-04 04:23:14
合計ジャッジ時間 5,908 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 200003
#define MOD 1000000007
#define INF 1000000000

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+1,0);
  for(int i=0;i<N;i++){
    sum[i+1]=sum[i]+a[i];
  }

  ll ans=0;
  for(int i=1;i<=N/2;i++){
    ans=max<ll>(ans,sum[N]-sum[N-i]+sum[i]-(ll)i*(a[i-1]+a[N-i]));
    if(i+1<=N-i){
      ans=max<ll>(ans,sum[N]-sum[N-i]+sum[i]-(ll)i*2*a[i]);
    }
  }
  cout<<ans<<endl;
}
0