結果

問題 No.972 選び方のスコア
ユーザー eQeeQe
提出日時 2020-04-02 03:10:48
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 916 bytes
コンパイル時間 2,346 ms
コンパイル使用メモリ 146,152 KB
実行使用メモリ 6,848 KB
最終ジャッジ日時 2023-09-09 22:41:10
合計ジャッジ時間 7,507 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
6,476 KB
testcase_01 AC 112 ms
6,472 KB
testcase_02 AC 106 ms
6,400 KB
testcase_03 AC 52 ms
5,708 KB
testcase_04 AC 103 ms
6,556 KB
testcase_05 AC 103 ms
6,480 KB
testcase_06 AC 103 ms
6,676 KB
testcase_07 AC 84 ms
6,088 KB
testcase_08 AC 95 ms
6,528 KB
testcase_09 AC 90 ms
6,500 KB
testcase_10 AC 91 ms
6,516 KB
testcase_11 AC 95 ms
6,756 KB
testcase_12 AC 95 ms
6,472 KB
testcase_13 AC 97 ms
6,596 KB
testcase_14 AC 96 ms
6,484 KB
testcase_15 AC 97 ms
6,556 KB
testcase_16 AC 99 ms
6,456 KB
testcase_17 AC 98 ms
6,556 KB
testcase_18 AC 3 ms
4,912 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 96 ms
6,744 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 3 ms
5,112 KB
testcase_26 AC 3 ms
5,056 KB
testcase_27 AC 3 ms
4,956 KB
testcase_28 AC 3 ms
5,108 KB
testcase_29 AC 3 ms
4,964 KB
testcase_30 AC 2 ms
5,244 KB
testcase_31 AC 3 ms
5,040 KB
testcase_32 AC 3 ms
5,060 KB
testcase_33 AC 2 ms
5,200 KB
testcase_34 AC 3 ms
5,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <string>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) (a)=max(a, b)
#define chmin(a, b) (a)=min(a, b)
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;


/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/



int main(void) {
  ll i, j, k;
  
  ll N;
  cin >> N;
  ll a[MAX*2];
  ll s[MAX*2]={};
  
  for(i=1; i<=N; i++) cin >> a[i];
  sort(a+1, a+N+1);
  for(i=1; i<=N; i++) s[i]=s[i-1]+a[i];
  
  ll ans=0;
  for(i=1; i<=N; i++) {
    
    ll l=0, r=min(i-1, N-i)+1;
    while(l+1<r) {
      ll m=(l+r)/2;
      ll t=(s[N]-s[N-m])+(s[i-1]-s[i-1-m])-a[i]*2*m;
      chmax(ans, t);
      (t>0 ? l:r)=m;
    }
    
    //chmax(ans, (s[N]-s[N-l])+(s[i-1]-s[i-1-l])-a[i]*2*l);
    
  }
  
  pt(ans);
  
}

0