結果

問題 No.198 キャンディー・ボックス2
コンテスト
ユーザー fura
提出日時 2020-04-25 21:18:36
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 410 bytes
コンパイル時間 1,728 ms
コンパイル使用メモリ 198,748 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-11-26 11:44:02
合計ジャッジ時間 2,524 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |         lint b; scanf("%lld",&b);
      |                 ~~~~~^~~~~~~~~~~
main.cpp:10:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |         int n; scanf("%d",&n);
      |                ~~~~~^~~~~~~~~
main.cpp:12:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |         rep(i,n) scanf("%lld",&c[i]);
      |                  ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

int main(){
	lint b; scanf("%lld",&b);
	int n; scanf("%d",&n);
	vector<lint> c(n);
	rep(i,n) scanf("%lld",&c[i]);

	lint ub=(b+accumulate(c.begin(),c.end(),0LL))/n;

	sort(c.begin(),c.end());
	lint med=c[n/2];

	lint ans=0;
	rep(i,n) ans+=abs(c[i]-min(ub,med));
	printf("%lld\n",ans);

	return 0;
}
0