結果
問題 |
No.837 Noelちゃんと星々2
|
ユーザー |
![]() |
提出日時 | 2019-07-02 15:50:27 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 673 bytes |
コンパイル時間 | 571 ms |
コンパイル使用メモリ | 62,096 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-22 11:08:41 |
合計ジャッジ時間 | 2,966 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 8 WA * 21 |
ソースコード
#include<iostream> #include<algorithm> #include<vector> using namespace std; int main(){ int N; cin >> N; int Y[N]; for(int i=0;i<N;i++){ cin >> Y[i]; } sort(Y,Y+N); int j; int mx=0; for(int i=0;i<N-1;i++){ if(Y[i+1]-Y[i]>=mx){ mx=Y[i+1]-Y[i]; //cout << mx << endl; j=i; } } if(mx==0){ cout << 1 << endl; return 0; } //cout << j << endl; long long ans=0; int f=j/2; int b=(N+j)/2; for(int i=0;i<=j;i++){ ans+=abs(Y[i]-Y[f]); } for(int i=j+1;i<N;i++){ ans+=abs(Y[i]-Y[b]); } cout << ans << endl; }