結果
問題 | No.972 選び方のスコア |
ユーザー |
|
提出日時 | 2020-01-17 22:59:55 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 111 ms / 2,000 ms |
コード長 | 442 bytes |
コンパイル時間 | 555 ms |
コンパイル使用メモリ | 69,820 KB |
実行使用メモリ | 7,244 KB |
最終ジャッジ日時 | 2024-06-25 23:43:57 |
合計ジャッジ時間 | 4,332 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
コンパイルメッセージ
main.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 7 | main() | ^~~~
ソースコード
#include<iostream> #include<algorithm> using namespace std; int N; long A[2<<17]; long S[2<<17]; main() { cin>>N; for(int i=0;i<N;i++)cin>>A[i]; sort(A,A+N); for(int i=0;i<N;i++)S[i+1]=S[i]+A[i]; long ans=0; for(int i=1;i<N-1;i++) { int lim=min(i,N-1-i); long L=0,R=lim+1; while(R-L>1) { long M=(L+R)/2; if(A[N-M]+A[i-M]>A[i]*2)L=M; else R=M; } ans=max(ans,S[N]-S[N-L]+S[i]-S[i-L]-2*L*A[i]); } cout<<ans<<endl; }