結果
| 問題 | 
                            No.972 選び方のスコア
                             | 
                    
| コンテスト | |
| ユーザー | 
                             amaridekinai
                         | 
                    
| 提出日時 | 2020-01-17 22:20:05 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 518 bytes | 
| コンパイル時間 | 1,858 ms | 
| コンパイル使用メモリ | 171,800 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-06-25 21:10:46 | 
| 合計ジャッジ時間 | 5,311 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 25 WA * 7 | 
ソースコード
#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]);
    
  }
  
  cout << ans << endl;
  
  return 0;
}
    
            
            
            
        
            
amaridekinai