結果
問題 | No.198 キャンディー・ボックス2 |
ユーザー |
![]() |
提出日時 | 2015-04-29 21:42:26 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 522 bytes |
コンパイル時間 | 1,090 ms |
コンパイル使用メモリ | 160,196 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-05 16:48:35 |
合計ジャッジ時間 | 1,890 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 WA * 5 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:14:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 14 | scanf("%lld%lld",&B,&N); | ~~~~~^~~~~~~~~~~~~~~~~~ main.cpp:15:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 15 | for(int i=0;i<N;i++)scanf("%lld",&A[i]); | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include<bits/stdc++.h>using namespace std;typedef long long ll;ll B,N,A[10];ll getLim(){ll ret=B;for(int i=0;i<N;i++)ret+=A[i];return ret;}ll ll_abs(ll val){return val>0?val:val*-1;}int main(){scanf("%lld%lld",&B,&N);for(int i=0;i<N;i++)scanf("%lld",&A[i]);ll lim=getLim();sort(A,A+N);ll to;if(A[(N-1)/2]>lim)to=lim;else to=A[(N-1)/2];ll ans=0;for(int i=0;i<N;i++){ans+=ll_abs(A[i]-to);}printf("%lld\n",ans);return 0;}