結果

問題 No.972 選び方のスコア
ユーザー butsurizukibutsurizuki
提出日時 2020-05-29 03:18:19
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 1,083 bytes
コンパイル時間 995 ms
コンパイル使用メモリ 29,500 KB
実行使用メモリ 11,292 KB
最終ジャッジ日時 2023-08-03 22:09:10
合計ジャッジ時間 4,409 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
9,252 KB
testcase_01 AC 69 ms
11,292 KB
testcase_02 AC 64 ms
9,132 KB
testcase_03 AC 34 ms
7,948 KB
testcase_04 AC 68 ms
11,168 KB
testcase_05 AC 67 ms
11,116 KB
testcase_06 AC 67 ms
11,240 KB
testcase_07 AC 52 ms
8,048 KB
testcase_08 AC 47 ms
10,408 KB
testcase_09 AC 45 ms
8,396 KB
testcase_10 AC 40 ms
8,140 KB
testcase_11 AC 41 ms
10,496 KB
testcase_12 AC 43 ms
10,580 KB
testcase_13 AC 46 ms
11,192 KB
testcase_14 AC 44 ms
10,596 KB
testcase_15 AC 57 ms
11,108 KB
testcase_16 AC 56 ms
9,256 KB
testcase_17 AC 55 ms
8,972 KB
testcase_18 AC 2 ms
6,512 KB
testcase_19 AC 66 ms
8,912 KB
testcase_20 AC 67 ms
9,256 KB
testcase_21 AC 66 ms
8,892 KB
testcase_22 AC 64 ms
8,848 KB
testcase_23 AC 67 ms
11,204 KB
testcase_24 AC 65 ms
11,128 KB
testcase_25 AC 3 ms
6,916 KB
testcase_26 AC 3 ms
7,272 KB
testcase_27 AC 2 ms
6,136 KB
testcase_28 AC 3 ms
6,712 KB
testcase_29 AC 3 ms
7,612 KB
testcase_30 AC 3 ms
7,028 KB
testcase_31 AC 3 ms
6,740 KB
testcase_32 AC 2 ms
6,272 KB
testcase_33 AC 2 ms
6,324 KB
testcase_34 AC 2 ms
6,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//set many funcs template
//Ver.20190820
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#include<assert.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384
#define size 524288

long long llmax(long long a,long long b){if(a>b){return a;}return b;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}

int main(void){
  long long i,j,n,m,k,a[size],b,c,h,w,r=0,l,t;
  long long rw[size]={0};
  long long st,fi,te;
  scanf("%lld",&n);
  for(i=1;i<=n;i++){
    scanf("%lld",&a[i]);
  }
  qsort(&a[1],n,sizeof(long long),llsortfncsj);

  for(i=1;i<=n;i++){rw[i]=rw[i-1]+a[i];}

  if(n<=2){puts("0");return 0;}

  for(i=2;i<=n-1;i++){
    st=1;fi=(i-1);
    while(st<=fi){
      te=(st+fi)/2;
      if(a[n+1-te]+a[i-te]-2*a[i]<0){fi=te-1;}
      else{st=te+1;}
    }
    w=(rw[i]-rw[i-fi-1])+(rw[n]-rw[n-fi]);
    r=llmax(w-(2*fi+1)*a[i],r);
  }
  printf("%lld\n",r);
  return 0;
}
0