結果

問題 No.972 選び方のスコア
ユーザー butsurizukibutsurizuki
提出日時 2020-05-29 03:18:19
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 1,083 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 31,360 KB
実行使用メモリ 8,960 KB
最終ジャッジ日時 2024-04-21 20:57:00
合計ジャッジ時間 3,318 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
8,832 KB
testcase_01 AC 70 ms
8,832 KB
testcase_02 AC 67 ms
8,704 KB
testcase_03 AC 37 ms
7,424 KB
testcase_04 AC 69 ms
8,960 KB
testcase_05 AC 69 ms
8,832 KB
testcase_06 AC 69 ms
8,832 KB
testcase_07 AC 54 ms
8,064 KB
testcase_08 AC 49 ms
8,192 KB
testcase_09 AC 49 ms
7,936 KB
testcase_10 AC 46 ms
8,064 KB
testcase_11 AC 46 ms
8,064 KB
testcase_12 AC 47 ms
8,064 KB
testcase_13 AC 51 ms
8,960 KB
testcase_14 AC 47 ms
8,064 KB
testcase_15 AC 59 ms
8,832 KB
testcase_16 AC 58 ms
8,832 KB
testcase_17 AC 58 ms
8,832 KB
testcase_18 AC 5 ms
5,888 KB
testcase_19 AC 69 ms
8,832 KB
testcase_20 AC 68 ms
8,960 KB
testcase_21 AC 68 ms
8,960 KB
testcase_22 AC 69 ms
8,704 KB
testcase_23 AC 70 ms
8,960 KB
testcase_24 AC 68 ms
8,832 KB
testcase_25 AC 4 ms
5,760 KB
testcase_26 AC 4 ms
5,760 KB
testcase_27 AC 4 ms
5,760 KB
testcase_28 AC 4 ms
5,760 KB
testcase_29 AC 4 ms
5,760 KB
testcase_30 AC 4 ms
5,888 KB
testcase_31 AC 4 ms
5,888 KB
testcase_32 AC 4 ms
5,760 KB
testcase_33 AC 4 ms
6,016 KB
testcase_34 AC 4 ms
5,888 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