結果

問題 No.972 選び方のスコア
ユーザー butsurizukibutsurizuki
提出日時 2020-05-29 03:18:01
言語 C
(gcc 12.3.0)
結果
RE  
実行時間 -
コード長 1,079 bytes
コンパイル時間 1,630 ms
コンパイル使用メモリ 31,104 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 20:56:17
合計ジャッジ時間 7,175 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 1 ms
5,376 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 1 ms
5,376 KB
testcase_33 RE -
testcase_34 RE -
権限があれば一括ダウンロードができます

ソースコード

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 64

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