結果
| 問題 | 
                            No.198 キャンディー・ボックス2
                             | 
                    
| コンテスト | |
| ユーザー | 
                             あかりき
                         | 
                    
| 提出日時 | 2021-03-15 00:00:04 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                RE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 375 bytes | 
| コンパイル時間 | 303 ms | 
| コンパイル使用メモリ | 81,964 KB | 
| 実行使用メモリ | 170,200 KB | 
| 最終ジャッジ日時 | 2024-11-06 12:05:54 | 
| 合計ジャッジ時間 | 9,813 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 15 WA * 8 RE * 3 | 
ソースコード
b=int(input())
n=int(input())
c=[int(input()) for i in range(n)]
c.sort()
if n//2==1:
  t=c[n//2]
else:
  t=(c[n//2-1]+c[n//2])//2
ans=[]
for i in range(max(t-10**6,0),t+10**6):
  ct=0
  y=b
  for j in range(n):
    if c[j]>=i:
      ct+=c[j]-i
      y+=c[j]-i
  for j in range(n):
    if c[j]<i:
      ct+=i-c[j]
      y-=i-c[j]
  if y>=0:
    ans.append(ct)
print(min(ans))
            
            
            
        
            
あかりき